Tuesday, July 28, 2009

How do you call a javascript function from C# code in ASP.NET?

Or does this idea even make any sense?





10 pts for the first correct answer that works!





Seems easy enough. I have a javascript function defined in the .aspx file, and I want to call said function from inside the corresponding .aspx.cs file.

How do you call a javascript function from C# code in ASP.NET?
Just Response.Write a string that will call the function. For example:





MyFile.aspx





%26lt;script language="JavaScript"%26gt;


function Hello()


{


alert("Hello!");


}


%26lt;/script%26gt;





And, in your codebehind file just Response.Write out a script block that calls the function. Yahoo! seems to filter out my code, so I can't fully post it.


No comments:

Post a Comment