Mutual call between C # function and JavaScript function
This article mainly talks about "the mutual call between C# function and JavaScript function". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "the mutual call between C# function and JavaScript function"!
We answer the mutual calls between the C # function and the JavaScript function by way of question and answer.
How do I access C # functions in JavaScript? The answers to the questions are as follows:
Execute the function in the C# code in the JavaScript function:
Method 1:
1. First set up a button to write the called or processed content to the button_click in the background.
2. Write a js function in the foreground with the content document.getElementById ("btn1"). Click ()
3. Call the js function in the foreground or background to fire the click event, which is equal to visiting the background C# function
Method 2:
1. The function is declared as public
Background code (you can also change public to protected)
Publicstringss () {return ("a");}
2. In html, you can call
Foreground script
Vara= ""; alert (a); script >
Method 3:
Function__doPostBack (eventTarget,eventArgument)
{
VartheForm=document.Form1;// refers to the form of runat=server
TheForm.__EVENTTARGET.value=eventTarget
TheFrom.__EVENTARGUMENT.value=eventArgument
TheForm.submit ()
}
Script >
At this point, I believe you have a deeper understanding of the "mutual call between C# function and JavaScript function". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!