Mutual calls between the Asp.net server and client

Source: Internet
Author: User
The script call between ASP. NET server and client has been plagued for a long time, so far it has not been possible to achieve the ideal call method.
1. Methods for ASP. NET Server to call client scripts.
<Script language = "javascript">
Function bclick ()
{
Document. getElementById ("div10"). style. display = 'none ';
}
</Script>
Call method:
Button1.Attributes. Add ("onclick", "bclick ()");
This is postback, so the div10 after execution cannot be hidden. This problem has been bothering me for a long time. If you know it, please give me some advice! Thank you very much!

2. Methods for ASP. NET Server to call client scripts.
ScriptManager. RegisterStartupScript (this. Page, typeof (string), "addV", "document. getElementById ('did10'). style. display = 'none';", true );
Appendix:
Page. RegisterStartupScript sends the script block at the end of the Web form (before the </form> identifier.
RegisterStartupScript () is used to add the script block to run after the page is loaded. The script block added in this way is located at the end of the Web form, because the HTML elements to be modified must be defined before the script runs. That is, if you want to use a client script to set the focus to the text box, make sure that the HTML mark of the text box is before the script that sets the focus of the text box.
Page. RegisterClientScriptBlock method:
The client script is issued after the start mark of the <form runat = "server"> element of the Page object.
The RegisterClientScriptBlock () method is used for script code executed to respond to client events. The script block sent by this method is located at the beginning of the Web page, because this method does not require that the script block be placed after all HTML elements, that is, it generally does not use custom controls in the document

3. The client calls the server method.
A. Foreground: <% # GetScore (Container. DataItem, "score") %>
Background:
Public string GetScore (object container, string score)
{
String _ score = DataBinder. GetPropertyValue (container, score). ToString ();
Int scoresum = Convert. ToInt32 (_ score) + 10;
Return Convert. ToString (scoresum );
}
B. Use Ajax frameworks such as AjaxPro. Net and Atheme.net for processing. These frameworks are indeed very convenient when clients call server methods.

4. Use Asp.net Ajax for processing. The special effects and functions of Asp.net make it easy to not refresh the processing and improve the efficiency.

   

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.