0

I have the following scenario:

On click of a SAVE button in aspx page,some processing will take place. The processing can be of 10-15 minutes. I want to disable the SAVE button till process ends and once process completes, the SAVE button should be enabled.

I tried the following but could not solve the problem:

1) Client Side Scripting:

I called a JavaScript on client click of button and set the disable property to true. However, server side saveButton_Click event is not called because of disabling the button on client side.

2) Disabling in saveButton_Click method on server side:

In this case, as the call of saveButton_Click already happened and requested is sent to server, the client side is as it without any difference until the request is processed.

halfer
  • 19,824
  • 17
  • 99
  • 186
ASD
  • 1,441
  • 3
  • 28
  • 41

6 Answers6

0

You can handled it simply by this code.Suppose, here is a button named btnAdd.When you click this button it will be disable due to execute it's corresponding code.I mean due to post back it will be disabled.

if (!IsPostBack)
    {
     btnAdd.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(btnAdd).ToString());
    }
yeasir007
  • 2,110
  • 2
  • 28
  • 43
0

You said: "1)Client Side Scripting: I called a java script on client clik of button and set the disable property to true.How ever, server side saveButton_Click event is not called because of disabling the button on client side." and this means the button is now disabled and call to the server side will not be processed untill you re-enabale the button. So is it not meeting your requirement?

Kangkan
  • 15,267
  • 10
  • 70
  • 113
0

Use System.Threading.Thread.Sleep(5000) in your button click and make it disabled...

For ref Disable submit button

ACP
  • 34,682
  • 100
  • 231
  • 371
0

You could use a dummy submit button:

<%@ Page Language="C#" AutoEventWireup="true" %>
<script type="text/C#" runat="server">
    protected void BtnClick(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(2000);
        result.Text = DateTime.Now.ToLongTimeString();
    }
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <button type="button" onclick="this.disabled='disabled';document.getElementById('<%= btn.ClientID %>').click();">Start processing</button>
    <asp:Button ID="btn" runat="server" OnClick="BtnClick" style="display:none;" />
    <asp:Label ID="result" runat="server" />
    </form>
</body>
</html>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • @Darin plz help me out http://stackoverflow.com/questions/2507844/how-to-use-jquery-to-paginate-json-data – ACP Mar 25 '10 at 11:58
0

Set OnClientClick and UseSubmitBehavior in your button markup

 OnClientClick="this.disabled = true; this.value = 'Submitting...';" UseSubmitBehavior="false"
Adam
  • 2,632
  • 8
  • 34
  • 60
0

Don't disable the button. As you said it won't fire the server side event. Alternatively you can hide the button and show some proper message (like 'processing..', 'working..'). This will give nice interface. And you will give the effect of disabling button on postback and enabling the button after postback.

Sangam Uprety
  • 1,482
  • 2
  • 20
  • 38