tags:

views:

176

answers:

2

hi, i need to disable the button during the click and need to enable after my server side event is done right now my code looks like this

$(document).ready(function(){ $('.saveButton').bind("click", function(e) { $(this).attr("disabled", "true"); return true; //causes the client side script to run. }); });

//this works finr for disableing the button //how to enable the button from disabled to enable after my server side event as executed

//Server side events protected void Button1_Click(object sender, EventArgs e) { try { } catch() { } finally { //once my control reaches here i need to enable my save from disabled to enabled stae // can we do this in jQuery } } looking for this code from PAST 2 DAYS any solution on this would be great thank you thank you

+3  A: 

You can use the RegisterClientScriptBlock method on your Button1_Click event, to add client scripts from the server-side:

var enableButton = "$('.saveButton').removeAttr('disabled');";
Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "EnableButton",
                                            enableButton, true);
CMS
+1  A: 

I think the core issue here is your understanding of the page lifecycle, you might want to read up on it here http://msdn.microsoft.com/en-us/library/ms178472.aspx.

It looks like you don't necessarily want to post the page back. Consider updating the server using jQuery ajax and in the callback from that, re-enable the button.

Alternatively, this will re-enable the button after 5 seconds (after postback(hopefully!))

$(document).ready(function()
    { $('.saveButton').bind("click", function(e) {
         $(this).attr("disabled", "true"); 
        setTimeout(function(){$(this).removeAttr("disabled");}, 5000);
         return true; 
         }); 
    });

Or, at the end of your button click event write into a literal control something like this: "$(document).ready(function(){$('jQueryButtonSelector').removeAttr('disabled');});"

Or do the same using response.write()

Mike
hey what is happening here is the button is getting disabled fine once i click the button.but now it is not calling my server side event only i.eprotected void Button1_Click(object sender, EventArgs e) { /// my code }
prince23