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

by brunofig 25. April 2007 01:31

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?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.7
Theme by Mads Kristensen

About the author

Hi!

My name is Bruno and I'am a senior consultant. When I'm not working, you can catch me playing with my daugther, taking photos and hanging out with my wife and friends. :)

You can also check my dark side or have fun with my vision of the world.

View Bruno Figueiredo's profile on LinkedIn

TwitterCounter for @brunoshine

Ads

    Page List

      Most comments

      ricos ricos
      1 comments
      be Belgium
      Root Server Root Server
      1 comments
      de Germany
      steph steph
      1 comments
      sg Singapore

      RecentComments

      Comment RSS

      Now Reading

      Professional WCF Programming: .NET Development with the Windows Communication Foundation (Programmer to Programmer) by Scott Klein
      Professional Windows Workflow Foundation by Todd Kitta

      Popuri.us

      My Popularity (by popuri.us)