views:

21

answers:

1

I wanted to disable a button after it is clicked and at the same time fire the post back event to generate a report. My first set of code did not work because soon after the button is disabled the page won't submit/post back. here's the first set of code which was not implemented. the onclientclick calls a javascript function which has these lines

document.getElementById('btnGenerateReport').disabled=true; GetPostBackEventReference(btnGenerateReport,'');

since it was not posting back

i tried the following on page_load code behind

btnGenerateReport.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(btnGenerateReport, ""))

that worked well. but I tried to copy the javascript that got generated and pasted directly on design view

onclick="this.disabled=true;__doPostBack('btnDownloadClientsWithConviction','');" 

its not working from client side alone after I disable the code behind attributes.add but when I check the view source the 2 pages are the same

why am I not able to move the code from code-behind to design view?

+1  A: 

Because the Button.ClientId is generated using a NamingContainer.

Try this instead:

document.getElementById('<%= btnGenerateReport.ClientId %>').disabled=true; 
GetPostBackEventReference('<%= btnGenerateReport.ClientId %>','');
rick schott
well rick schott, I checked the clientid before writing the code and the client id generated is same as the id in design view. only in certain situations asp.net create a different client id different from the id in design view. for eg: controls inside user controls.
Enggr
Depends on if you are using run="server" or .NET 4 ClientId options.
rick schott