我想在单击按钮后禁用该按钮,同时触发回发事件以生成报告。我的第一组代码不起作用,因为禁用按钮后不久,页面将不会提交/回发。这是第一组未实现的代码。 onclientclick 调用一个包含这些行的 javascript 函数
document.getElementById('btnGenerateReport').disabled=true; GetPostBackEventReference(btnGenerateReport,'');
因为它没有回发
我在 page_load 代码后面尝试了以下操作
btnGenerateReport.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(btnGenerateReport, ""))
效果很好。但我尝试复制生成的 JavaScript 并直接粘贴到设计 View
onclick="this.disabled=true;__doPostBack('btnDownloadClientsWithConviction','');"
在我禁用attributes.add后面的代码后,它不能单独从客户端工作 但是当我检查 View 源时,两个页面是相同的
为什么我无法将代码从代码隐藏移动到设计 View ?
最佳答案
因为 Button.ClientId 是使用 NamingContainer 生成的.
试试这个:
document.getElementById('<%= btnGenerateReport.ClientId %>').disabled=true;
GetPostBackEventReference('<%= btnGenerateReport.ClientId %>','');
关于javascript - 将 javascript 代码移动到设计 View 不起作用。仅代码隐藏 Attributes.Add ("onclick"有效。困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3258186/