.NET Articles, Web Devploment, ASP.NET, HTML, Sharepoint 2010, Aamir Hasan
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here



Posted by Mairaj   on Sunday, June 10, 2012 Total Views:  

Sometimes you want to call javascript finctions from code behind.In this case you would use ClientScriptManager to do this.Let’s see an example.Here we would call a javascript function which shows an alert.Create a function in javascript ShowAlert().On Page_Load we will call this function.

Desgin code


<head runat="server">


    <script type="text/javascript">

        function ShowAlert() {

            alert('This is being called from code behind');





    <form id="form1" runat="server">




    <p><a href="">ASP.NET controls with jquery</a></p>




Code behind

Now we will call the above javscript method from server side by using RegisterStartupScript


   protected void Page_Load(object sender, EventArgs e)


        ClientScriptManager cs = Page.ClientScript;

        cs.RegisterStartupScript(this.GetType(), "script", "ShowAlert();", true);



Here you would have noted that the RegisterStartupScript method of ClientScriptManager class accepts four parameters.

  1. Control that registers the Script. Here page is registerig the script.
  2. This could be any key you want to write but make sure another script is not registered with this key.
  3. The script to be executed.Here you can write name of method to be executed or you can write script directly.
  4. Script tags to be added.true for yes false for not.

Microsoft Reference

ClientScriptManager.RegisterStartupScript Method


Download (980.00 bytes)


See live demo

Protected by Copyscape Online Plagiarism Tool
Go Here
Go Here United States
12/12/2021 4:42:09 AM #

Whether you are actually buying the real vintage furniture, you can be certain that these would be actually valuable pieces.

Website United States
2/19/2022 8:51:55 PM #

Good web site! I really love how it is simple on my eyes and the data are well written. I'm wondering how I could be notified when a new post has been made. I have subscribed to your feed which must do the trick! Have a nice day!

Add comment

  Country flag

  • Comment
  • Preview

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5