Asp.net 单击时禁用按钮,然后在刷新后启用
我在一个页面上有一个按钮,当单击该按钮时,会运行一个子按钮,用SQL表中的数据填充gridview。我正在用VB使用VS2010 当用户单击submit按钮时,我想立即禁用它,然后运行sub,一旦sub运行,再次启用按钮 我将下面的内容添加到按钮单击事件中,但它不起作用Asp.net 单击时禁用按钮,然后在刷新后启用,asp.net,vb.net,button,Asp.net,Vb.net,Button,我在一个页面上有一个按钮,当单击该按钮时,会运行一个子按钮,用SQL表中的数据填充gridview。我正在用VB使用VS2010 当用户单击submit按钮时,我想立即禁用它,然后运行sub,一旦sub运行,再次启用按钮 我将下面的内容添加到按钮单击事件中,但它不起作用 imgbtnComDetailGo.enabled = False Call Sub() imgbtnComDetailGo.enabled = True 它似乎不会立即禁用按钮 更新-我在谷
imgbtnComDetailGo.enabled = False
Call Sub()
imgbtnComDetailGo.enabled = True
它似乎不会立即禁用按钮
更新-我在谷歌上找到了这段代码
OnClientClick="this.disabled = true" UseSubmitBehavior="true"
但是它似乎没有调用SUB,因为除了按钮被禁用之外,没有任何事情发生。从代码隐藏处将javascript附加到按钮(例如页面加载事件): 如果您的页面具有验证程序,请在分配给按钮的OnClientClick之前,使用附加脚本包装上述sJavaScript:
sJavaScript = "if (typeof(Page_ClientValidate) == 'function') {if (Page_ClientValidate()) {" & sJavaScript & ";}}"
我已经用一些脚本完成了。以下是代码: 在实用程序文件中使用此选项,并在需要时调用 C# 在页面加载时,您只需调用
Util.SubmitDisable(这个按钮是NID)代码>
CSS:
.ButtonPleaseWait { background: #F3F3F3 url('../images/pleasewait.gif') no-repeat 2px center; border: thin solid #000; width: 100px; height: 25px; color: #333; font-weight: bold; text-indent: 15px; font-size: 1.13em; }
asp.net
只需在asp.net按钮中使用UseSubmitBehavior=“false”
,尝试使用ajax即可。我假设这是asp.net?好的-我已经添加了标记。对于将来的问题,请适当标记WinForms/ASP.NET/WPF等,因为这有助于获得正确答案没有问题,谢谢发布按钮1单击事件标记?
public static void SubmitDisable(System.Web.UI.Page source, ref System.Web.UI.WebControls.Button button)
{
string script = null;
script += "if (typeof(Page_ClientValidate) == 'function')";
script += "{";
//script += " /if client-side does not validate, stop (this supports validation groups)";
//script += " //however before validating attempt, must save and, then restore the page validation / submission state, otherwise";
//script += " //when the validation fails, it prevents the FIRST autopostback from this/other controls";
script += " var oldPage_IsValid = Page_IsValid;";
script += " var oldPage_BlockSubmit = Page_BlockSubmit;";
script += " if (Page_ClientValidate('" + button.ValidationGroup + "') == false)";
script += " {";
script += " Page_IsValid = oldPage_IsValid;";
script += " Page_BlockSubmit = oldPage_BlockSubmit;";
script += " return false;";
script += " }";
script += "}";
//script += "//change button text and disable it";
script += "this.className = 'ButtonPleaseWait';";
script += "this.value = 'Working ...';";
script += "this.disabled = true;";
//script += "//insert the call to the framework JS code that does the postback of the form in the client";
//script += "//The default code generated by ASP (WebForm_DoPostbackWithOptions) will not ";
//script += "//submit because the button is disabled (this is new in 2.0)";
script += source.ClientScript.GetPostBackEventReference(button, null) + ";";
//script += "//MUST RETURN AFTER THIS, OTHERWISE IF THE BUTTON HAS UseSubmitBehavior=false";
//script += "//THEN ONE CLICK WILL IN FACT CAUSE 2 SUBMITS, DEFEATING THE WHOLE PURPOSE";
script += "return true;";
button.Attributes.Add("onclick", script);
}
.ButtonPleaseWait { background: #F3F3F3 url('../images/pleasewait.gif') no-repeat 2px center; border: thin solid #000; width: 100px; height: 25px; color: #333; font-weight: bold; text-indent: 15px; font-size: 1.13em; }