Function call between C # And Javascript

Source: Internet
Author: User
C # interaction with JavaScript

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:
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
Public String getauthstatus ()
{
Viewstate ["auth"] = "red ";
Return viewstate ["auth"]. tostring ();
}
JavaScript code
Function getauth ()
{
VaR authstatus = "<% = getauthstatus () %> ";
Return authstatus;
}
If the C # method called by JavaScript does not return a value, you can put a button on one side and then write what you want to do in the Click Event of the button, write the following code in the client script.
Document. All ("button1"). Click ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.