简体   繁体   English

回发过程中的ASP禁用按钮

[英]ASP disable button during postback

I have a button which i am trying to add a css class to appear disabled once the user has clicked it. 我有一个按钮,我试图添加一个CSS类,一旦用户单击它,它将显示为已禁用。

protected void Button_Continue_OnClick(object sender, EventArgs e)
    {
        Panel_Error.Visible = false;
        Literal_Error.Text = "";
        if (RadioButton_Yes.Checked)
        {
            ...//if radio checked get text and process etc.
        }
    }

My button onlick is above which simply processes a textbox filled on the page. 我的按钮onlick在上方,它仅处理页面上填充的文本框。

My button looks like this: 我的按钮如下所示:

<asp:Button runat="server" ID="Button_Continue" CssClass="button dis small" Text="Continue" OnClick="Button_Continue_OnClick" ClientIDMode="Static" OnClientClick="return preventMult();" />

And my javscript is as follows: 我的文字如下:

<script type="text/javascript">
var isSubmitted = false;
function preventMult() {
    if (isSubmitted == false) {
        $('#Button_Continue').removeClass('ready');
        $('#Button_Continue').addClass('disabled');
        isSubmitted = true;
        return true;
    }
    else {
        return false;
    }
}
</script>

The problem I am having is that the css class added works fine on the first postback, but after which my button onclick doesnt work and the button cant be clicked again if the user needs to resubmit the data if it is wrong 我遇到的问题是,添加的css类在第一次回发时能正常工作,但是此后我的按钮onclick无法正常工作,并且如果用户需要重新提交数据(如果输入错误),则无法再次单击该按钮

Another problem I am having is that with a breakpoint in my method i notice that the method is fired twice on the click. 我遇到的另一个问题是在方法中出现断点时,我注意到该方法在单击时被触发了两次。

Looks like you need something like this: 看起来您需要这样的东西:

private void Page_Load()
{
   if (!IsPostBack)
   {
    //doNothing
    }
else
    {
    //button.disabled = true
    }
}

尝试这个

<asp:Button runat="server" ID="Button_Continue" AutoPostBack="true" CssClass="button dis small" Text="Continue" OnClick="Button_Continue_OnClick" ClientIDMode="Static" OnClientClick="return preventMult();" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM