In Asp.net development, the background and foreground interactions are often used. In this case, a summary of how C # and JavaScript interact with each other is provided.
1. In the background C #CodeTo call jacascript.
JavaScript code:
< Script Type = " Text/JavaScript " Language = " Javascript " >
Function Test ()
{
Alert ( " Oec2003 " );
Return False ;
}
< / SCRIPT>
C # code:
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> protected void button#click ( Object sender, eventargs e)
{
Clientscript. registerstartupscript (This. GetType (),"Clear","<SCRIPT> test ()
</Script>");
}
2. Call the C # method in Javascript
If the method in C # has a return value, you can use the following method:
C # code:
Code
Public String Getauthstatus ()
{
Viewstate [ " Auth " ] = " Red " ;
Return Viewstate [ " Auth " ]. Tostring ();
}
JavaScript code
Function getauth ()
{
VaR authstatus = " <% = Getauthstatus () %> " ;
Return Authstatus;
}
If the C # method called in JavaScript does not return a value, you can put a button on one side and then
Click the button event to write what you want to do, and write the following code in the client script.
document. All ("button1"). Click ();