Click here to Skip to main content
15,887,442 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi how to call various javascripit method from code behind in asp.net
Posted
Comments
Diler Patel 16-May-13 9:51am    
Can u Tell Me What is MyScript in Below Code ?


Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript",
"javascript:TestJavascriptFunction();", true);

Using Page.ClientScript.RegisterStartupScript.
C#
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript",
   "javascript:TestJavascriptFunction();", true);
 
Share this answer
 
Comments
Uday P.Singh 20-Nov-11 2:59am    
5ed :)
RaisKazi 20-Nov-11 3:01am    
Thank you Uday.
thatraja 20-Nov-11 4:26am    
5!
RaisKazi 20-Nov-11 10:57am    
Thank you Raja.
Member 8150573 28-Sep-12 6:36am    
I have registered my button on page load function like this :
Button1.Attributes.Add("onclick", "alert('Error')");

But i dont want this attribute to execute all the time whenever i press the Button1, instead i have a condition inside the Button1_click depending on the condition i need to show the alert, so my concern is how to call this statement() inside my if condition.
Code snippt :
public void btn_ProjWiseRevCost_Click(System.Object sender, System.EventArgs e)
{
int a=1;
if( a == 0)
{
// Call that alert
}
}

Please someone help me.
 
Share this answer
 
Comments
thatraja 20-Nov-11 4:26am    
5!
Simple google search will answer this question. Try this:

Use & Call RegisterStartUpScript, RegisterClientScript and Client-Side Script[^]

hope it helps :)
 
Share this answer
 
Comments
thatraja 20-Nov-11 4:26am    
5!
Uday P.Singh 20-Nov-11 5:25am    
thank you Raja :)
my ascx page is not calling the javascripts
 
Share this answer
 

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