In ASP. NET, foreground variables or methods in the background and background are called.

Source: Internet
Author: User

I. frontend call background

1. the foreground calls the background variable (Note: The array variables cannot be obtained. You need to convert the separator into a string variable in the background, and then process the variable in the foreground as an array.)

The background page provides a global variable, which is assigned a value in page_load. The foreground uses <% = xxx %> to obtain the variable;

2. the foreground calls the background method (that is, Ajax. For details, see jquery. Bind the button to the click)

2. Call the foreground at the background

1. Use foreground variables in the background

Method 1: 1. the foreground uses static text controls to hide the field and write the JS variable value into it;
2. the backend uses request ["ID"] to obtain the value;
Method 2: cookie or session can be used

2. Use foreground functions in the background

(1) dynamically add scripts using the clientscript class(Better)

Foreground: function closewindow (){....}

Background: clientscript. registerstartupscript (clientscript. GetType (), "myscript", "<SCRIPT> closewindow (); </SCRIPT> ");

(2) onclientclick

<Asp: button id = "button1" runat = "server" text = "button" onclientclick = "client_click ()" onclick = "button#click"/>
Client_click () is a JavaScript method,Execute client_click ();

(3) button1.attributes. Add ("onclick", "Return client_click ()");

"Client_click ()" is a foreground method that can be replaced with a general script such as retrun confirm ('Are you sure you want to delete it? ')

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.