ASp.net RegisterClientScriptBlock

ASp.net RegisterClientScriptBlock


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.

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5