Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Hi,
I want to call javascript function from aspx.cs. In Button click I will check for some conditions, corresponding to that conditions I have to call javascript function. Is it possible
Posted

hi,
use this code in your method..
XML
Page.RegisterStartupScript("OnLoad","<script>functionName();</script>");

Hope This may help you..
 
Share this answer
 
Check out the links here: Google search - javascript from code behind[^]
 
Share this answer
 
Comments
Kasson 22-Dec-10 5:56am    
Good Call My 5.
Dalek Dave 22-Dec-10 6:37am    
Good Links.
Rajesh Anuhya 22-Dec-10 7:16am    
Good One
 
Share this answer
 
C#
if (!ClientScript.IsStartupScriptRegistered("alert"))
   {
       Page.ClientScript.RegisterStartupScript(this.GetType(),
           "alert", "alertMe();", true);
   }
 
Share this answer
 
It is very easy to call javascript function from code behind asp.net .

In .cs code write


C#
string url = "yourpage.aspx?ManiFestNumber=" + value;
               ScriptManager.RegisterClientScriptBlock(this, GetType(), "rates", "openWindow('" + url + "');", true);




in aspx page just write in this code




<script type="text/javascript">

    function openWindow(url)
{
    var w = window.open(url, '', 'width=1,height=1,toolbar=0,status=0,location=0,menubar=0,directories=0,
resizable=0,scrollbars=0');
    w.focus();
}






and Its done .........
http://thedotnetdeveloper.blogspot.in/2012/03/call-javascript-function-from-code.html[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900