Asp.Net issue: Why does the TextBox render postback scripts and a Button dosen't when the enable state is false?

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?


Beware of XHTML

David Hammond as wrote an article showing the other side of XHTML. A must read for all web developers @ Beware of XHTML.


Always And Forever Chocolate Puma

Lyrics

You, you keep on breakin' up
And try and walk away and
crawl right back and stay
Right back and stay


You, you keep on breakin' up
And try and walk away and
crawl right back and stay
Right back and stay


Chorus (x2)
It's the jelousy
That its got u sayin
All those things to me
so now u think im paying
See eventually we'll end up together
always and forever


You, you keep on breakin' up (x5)
And try and walk away and
crawl right back and stay
Right back and stay


It's the jelousy
That its got u sayin
All those things to me
so now u think im paying
See eventually we'll end up together
always and forever


You, you keep on breakin' up
And try and walk away and
crawl right back and stay
Right back and stay


What happens if you drive behind a 747?


About Me

I'm a Senior Consultant in the work, and a geek outside of it :P

Recent posts

Recent comments