简体   繁体   中英

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.

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.

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

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();" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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