Can any one please tell me why????
I have a page that disables a button server-side, but on the client-side theres a script that based on some values enables the button. On the page theres also a textbox with a required field validator.
What happens is that the validators are not fired.
After some source-code review and some "reflection" on the subject, I found that the AddAttributesToRender of the button only writes the postback scripts if the button is enabled:
protected override void AddAttributesToRender(HtmlTextWriter writer){ ... bool isEnabled = base.IsEnabled; string firstScript = string.Empty; if (isEnabled) { firstScript = Util.EnsureEndWithSemiColon(this.OnClientClick); if (base.HasAttributes) { string text3 = base.Attributes["onclick"]; if (text3 != null) { firstScript = firstScript + Util.EnsureEndWithSemiColon(text3); base.Attributes.Remove("onclick"); } } if (this.Page != null) { string secondScript = this.Page.ClientScript.GetPostBackEventReference(postBackOptions, false); if (secondScript != null) { firstScript = Util.MergeScript(firstScript, secondScript); } } } ... if (this.Enabled && !isEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); } base.AddAttributesToRender(writer);}
So I asked myself: "Is this the same for all controls?"
It seems not. After some more "reflection", now on the TextBox control, I came to the conclusion that it's control-base, since the TextBox renders the postback script regardless of it's enable state. Some have, others don't.
When more and more web application have client-scripts changing the controls, I can' t understand this decision. Can you?