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.