开发者

Moving the javascript code to design view is not working. Only code-behind Attributes.Add("onclick" works. Puzzled

开发者 https://www.devze.com 2023-01-07 03:22 出处:网络
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 pag

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;__doPostBac开发者_运维技巧k('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?


Because the Button.ClientId is generated using a NamingContainer.

Try this instead:

document.getElementById('<%= btnGenerateReport.ClientId %>').disabled=true; 
GetPostBackEventReference('<%= btnGenerateReport.ClientId %>','');
0

精彩评论

暂无评论...
验证码 换一张
取 消