ASp.Net day

Micro blog

ASp.net RegisterclientScriptBlock

May 25
by Satalaj 25. May 2009 14:21


To emmit script after loading of all controls at client side browser use this C# code

Now we will close the broser / popup window close on Save botton click

On save button click  we will write following code to close the window


string str = "opener.location.reload(true);self.close();";

Page.RegisterClientScriptBlock("xx", "<script>"+str+"</script>"); 

// this will emit after saving the page and

// it will colse the opened window and refresh parent window 
 

Alert Examle snippet

public void Page_Load(Object sender, EventArgs e)
      {

        if (!this.IsClientScriptBlockRegistered("MyFirstScript"))
        {
   
          // create script that is to be registered at client side.

              String scriptString = "<script language=\"JavaScript\">alert('Hello world'); </script>";

             this.RegisterClientScriptBlock("MyFirstScript", scriptString);

        }
      }

 


It will alert Hello world at cleint after loading all controls IE.

About Satalaj

My name is Satalaj. I'm 2010 asp.net MVP. I write technical stuff here. www.satalaj.com

Ads by Lake Quincy Media

The best inline translator

Live lookup to see what asp.net developers are searching