Get the App
SLTechnology News&Howtos  ›  Development  › 

Mutual call between C # function and JavaScript function

Shulou Source: shulou.com Published: 2022-06-03 17:09:12 10月01日 Update

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!

Tags: Functions clips content background methods foreground code buttons learning utility deeper events interests practicality practicality simplicity of operation ways more friends answers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info Microsoft Shulou Information Docker