-1

I have a textbox, that programatically i set it 'Enabled = false'. When the page, after this change, get a postback, this textbox return the enabled value to true. why?

I have the textbox into a updatepanel.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
FCarrasco
  • 1
  • 3
  • Are you setting in code-behind in the Page_Load event? – David Mar 18 '13 at 13:52
  • 1
    Please add some code and markup. – Brian Mains Mar 18 '13 at 13:53
  • 6
    As this is not the normal behavior, it's probably something in your code. And since you didn't provide any code - there is no way to help you... – Blachshma Mar 18 '13 at 13:53
  • I'm pretty sure what's happening is you're disabling the control via the UpdatePanel but when the post back occurs it's resetting everything - you would need to set Enabled to false even during the post back based on the conditions. – Mike Perrenoud Mar 18 '13 at 13:53
  • i´m setting this value on code-behind in a event for other control (a textchanged for other textbox explicit). – FCarrasco Mar 18 '13 at 13:56

2 Answers2

2

If you're setting it in code-behind in the Page_Load event, you need to remember that Page_Load occurs even on postbacks. You have two options.

Place it with in a block that checks to see if the page is a postback.

if(!Page.IsPostBack)
{
   TextBox1.Enabled = false;
}

or set it in Page_Init instead.

If you're not already familiar with it, be sure you understand the Page Lifecycle. This is must-know information for ASP.NET developers. Read about it at http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx

David
  • 72,686
  • 18
  • 132
  • 173
  • i understand you, however, this textbox not ever be enabled=false, i switch this attribute when other textbox fire the event "textchanged", and if the textbox that fire the event, have a especific value, i changed this other textbox to disabled. maybe i just evaluate the condition any way that i get a postback... but this condition have a lot of database querys that can slow the postback – FCarrasco Mar 18 '13 at 18:32
0

In the page_load, do the following:

If (IsPostBack) Then
    Textbox1.Enabled = False
End If
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • but this textbox not ever be enabled=false, i switch this attribute when other textbox fire the event "textchanged", and if the textbox that fire the event, have a especific value, i changed this other textbox to disabled. – FCarrasco Mar 18 '13 at 18:31