2013-06-18 136 views
0

我在页面上有一个按钮,当点击时该按钮运行一个使用SQL表中的数据填充gridview的子组件。我在VB中使用VS2010。点击后禁用按钮,然后在刷新后启用

当用户点击提交按钮时,我想立即禁用它,然后运行子工具,一旦子工具运行,再次启用按钮。

我添加了下面的按钮单击事件,但它不工作

 imgbtnComDetailGo.enabled = False 

    Call Sub() 
    imgbtnComDetailGo.enabled = True 

它似乎并没有被立即禁用按钮。

更新 - 我发现谷歌

OnClientClick="this.disabled = true" UseSubmitBehavior="true" 

这个代码,但它不会出现调用SUB从按钮被禁用没有任何反应分开。

+0

尝试使用Ajax来做到这一点。 –

+0

我认为这是ASP.NET? –

+0

是的,这是正确的 – Silentbob

回答

0

附加一个JavaScript的按钮从后面的代码(如Page_Load事件。):

sJavaScript = "this.value='Please wait...';" ' optional button text 
sJavaScript &= "this.disabled = true;" 
sJavaScript &= Page.ClientScript.GetPostBackEventReference(imgbtnComDetailGo, "") 

imgbtnComDetailGo.OnClientClick = sJavaScript 

如果你的页面有验证,包装与其他脚本上面sJavaScript分配到该按钮的OnClientClick这个前:

sJavaScript = "if (typeof(Page_ClientValidate) == 'function') {if (Page_ClientValidate()) {" & sJavaScript & ";}}" 
0

我已经用一些脚本完成了这个。这里是代码:

使用这个在您的实用程序文件并调用时,你需要

C#

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); 
     } 

在页面加载你只需要调用Util.SubmitDisable(this,buttonID);

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

只使用UseSubmitBehavior="false"在asp.net按钮