0

我在页面上有一个按钮,单击该按钮会运行一个子视图,该子视图会使用 SQL 表中的数据填充网格视图。我正在使用带有 VB 的 VS2010。

当用户单击提交按钮时,我想立即禁用它,然后运行子程序,一旦子程序运行,再次启用该按钮。

我在按钮单击事件中添加了以下内容,但它不起作用

        imgbtnComDetailGo.enabled = False

    Call Sub()
    imgbtnComDetailGo.enabled = True

它似乎不会立即禁用该按钮。

更新 - 我在谷歌上找到了这段代码

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

但它似乎没有调用 SUB,因为除了按钮被禁用之外什么都没有发生。

4

2 回答 2

0

Attach a javascript to the button from code behind (eg. Page_Load event):

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

imgbtnComDetailGo.OnClientClick = sJavaScript

In case your page has validators, wrap the above sJavaScript with additional script before assigning to the button's OnClientClick:

sJavaScript = "if (typeof(Page_ClientValidate) == 'function') {if (Page_ClientValidate()) {" & sJavaScript & ";}}"
于 2013-06-18T11:11:42.100 回答
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; }

只需UseSubmitBehavior="false"在您的 asp.net 按钮中使用

于 2013-06-19T10:59:58.580 回答