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.

asp net image uploadAsp.net Interview Questions for 2 years or 3 years experianceASp.net 2.0 step by step Membership Provider ASP.net File HandlingWhat is web garden in Asp.net?Asp.net Convert Image To Base64Asp.net Convert String To ImageAsp.net open new windowHack asp.netListBox Asp.net Binding csharpAsp.net How To Write a Cookie and Read

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.