Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Call javascript function from codebehind in asp.net

Aug 9, 2010
Here i will explain how to call javascript function from codebehind without assigning it to any control in asp.net.

We can call javascript functions in two ways

first way is


 System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "document.getElementById('" + button2.ClientID + "').style.display='none';", true);
Seconda way you can call javascript function also


System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "MyJavascriptFunction();", true); 
Like this we can call the javascript functions or buttons in codebehind without assigning it to any control

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

7 comments :

Anonymous said...

Hi..
Your site is really nice.i learned many things from this site.Please try to write the above article with some examples.This could be useful for the beginners like me.

1. RegisterClientScriptBlock

2.RegisterClientScriptInclude

3.RegisterStartupScript

4. RegisterOnSubmitStatement

Anonymous said...

I had a problem with typeof(Page) so I resorted to the following with success:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Script", "function();", true);

Manoj said...

worked for me...
Thank You a lot...

Gireesh said...

Its Not Working...........

Ramesh said...

yes its not working .....

Ramesh said...

we can call the alert from this method but call a function is not working ...!

parth shah said...

how to call code behind fuction from javascript????

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.