When a server control has two things in one of the following ways:
1. Server-Side Click events
2. Execute AJAX request when the client clicks
The desired effect:
Execute the AJAX request first and then decide whether to execute the server response event based on the AJAX results
When a server control performs both operations at the same time, it is difficult to achieve the desired effect due to the various factors such as network speed, response rate, networking environment, or the result of the latter covering the result of the former, or the result of the former.
So, I thought of a halfway way.
First, the server control is "hidden" (note that if the server-side control is directly visiable = False, the control will become a hidden field directly, the client will not get the corresponding ID when using JavaScript to manipulate him, so it can be hidden: width = " 1px "height=" 1px "or directly using div style=" Display:none ")
Second, generate a client label next to
Third, write the corresponding Ajax event for the client tag
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/
Four, when obtain the corresponding Ajax result, executes the simulation clicks the service side the Click event, specific please see the following code
Foreground code:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Test.aspx.cs" inherits= "test"%> DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Background code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class Test:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Btn_ok_click (object sender, EventArgs e)
{
Response.Write ("Server response Code");
}
Author: Cnblogs A cat-eating fish