asp.net OnClientClick not rendered for initially disabled Button

Question:

I have a disabled asp.Button, which I enable later with JavaScript. Like this

<asp:Button ID="btnSave" runat="server" Text="Save" Enabled="false" OnClientClick="; return ValidateFields();" OnClick="btnSave_Clicked" />

Answer:

However, the "onclick" method is not rendered as html when the control is disabled. My work around is to add the following code in PageLoad.

btnSave.Attributes["onclick"] = "return ValidateFields();";

转载于:https://www.cnblogs.com/zhangchenliang/archive/2011/07/12/2104437.html

猜你喜欢

转载自blog.csdn.net/weixin_33849942/article/details/93494934