• Home > Web Front-end > JS Tutorial > Summary of methods such as js calling the background and the background calling the frontend_javascript skills

    Summary of methods such as js calling the background and the background calling the frontend_javascript skills

    WBOY
    Release: 2016-05-16 16:52:15
    Original
    1541 people have browsed it

    JS calls the background, the background calls the frontend and other methods summary

    1. Execute the function in the C# code in the javaScript function:

    Method 1: 1. First create a button and put it in the background The content of the call or processing is written into Button1_Click;

    Copy code The code is as follows:

    protected void Button1_Click(object sender, EventArgs e)
    {
    this.TextBox1.Text = "voodooer";
    }

    2. You can call it like this in the foreground:
    Copy code The code is as follows:



    Method 2: 1. Declare the function as public or protected
    Copy code The code is as follows:

    public string ss()
    {
    return("voodooer");
    }

    2. Foreground calling method
    Copy code The code is as follows:



    Method three: 1.


    Method 4:
    Copy code The code is as follows:



    〈! --Used to store the functions you want to call--〉

    In .CS there are:
    Copy code The code is as follows:

    public Page_OnLoad()
    {
    if (!Page.IsPost())
    {
    string strFunName=Request.Form[ "FunName"]!=null?Request.Form["FunName"]:"";
    //Determine which function to call based on the value passed back
    switch(strFunName)
    {
    case " enter()":
    enter(); //Call this function
    break;
    case "other":
    //Call other functions
    break;
    default:
    //Call the default function
    break;
    }
    }
    }
    public void enter()
    {
    //...such as calculating a certain value
    }

    2. How to access C# variables in JavaScript?

    The answer is as follows:

    Method 1: 1. Access

    Method 2: 1. If PUBLIC STRING N is defined in the background; the format for referencing this variable in the front-end js is' <%=n%>' or " <%=n%> ; "

    Method 3: 1. Or you can register a script on the page after assigning values ​​to server-side variables

    " "

    tmp is a background variable, and then you can directly access temp in js to get the value.

    3. How to access existing variables of JavaScript in C#?

    The answer is as follows:

    Method 1: 1. Use static text control to hide the field in the frontend and change the js variable Write the value into it;

    2. Use request["id"] in the background to get the value;

    Method 2: You can use cookie or session

    4. How to use C# Access JavaScript functions in?

    The answer is as follows:

    Execute javaScript functions in c# code:

    Method 1: 1. Page.RegisterStartupScript("ggg"," ");

    Method 2: Use the Literal class, then
    Copy the code The code is as follows:

    private void Button2_Click(object sender, System.EventArgs e)
    {
    string str;
    str=" ";
    //Literal1.Visible=true;
    Literal1.Text=str;
    }
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template