|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
EnableViewState=False creates problems with Visible & Enabledand 2 Buttons (Button1 & Button2). Button1 checks if the TextBox is Visible (or Enabled) and sets it to False (or True in the opposite case). Button2 does absolutely nothing. If I set EnableViewState=False on the TextBox, I am no longer able to control the .Visible or .Enabled properties. Button1 will set .Visible=False, but will never set it to True again. Button2 (which does nothing) will bring it back up (eg set it back to it's original state). With EnableViewState=True, it works as expected. Button1 toggles TextBox1, Button2 does nothing. ------------ Code -------------- <script runat="Server"> Sub Button1_Click(ByVal sender As System.Object, ByVal e as System.EventArgs) TextBox1.Visible = Not (TextBox1.Visible) End Sub Sub Button2_Click(ByVal sender As System.Object, ByVal e as System.EventArgs) ' Do nothing End Sub </script> <html> <head><title>Form Test</title></head> <body> <form Runat="Server"> <asp:TextBox ID="TextBox1" EnableViewState="False" Runat="Server" /><br /> <asp:Button ID="Button1" Text="Submit" OnClick="Button1_Click" Runat="Server" /> <asp:Button ID="Button2" Text="Do Nothing" OnClick="Button2_Click" Runat="Server" /> </form> </body> </html> ------------ Code -------------- This is a small example the issue that I use in a much more complex state. I can write code to work around this (by explicitly setting Visible or Enabled in every single button (eg Button2), but this seems like much more work than necessary. Thank you in advance for any direction you can give. A Web application is stateless. A new instance of the Web page class is
created each time the page is requested from the server. This would ordinarily mean that all information associated with the page and its controls would be lost with each round trip. A server control's ViewState is the accumulation of all its property values. When you set the EnableViewState to false, the Visible value of the textbox on your page is reset to true (the default) upon every PostBack even if the PostBack does not execute any commands. If you want to decide some action based on the state of your textbox you have to turn the textbox's EnableViewState to true. Show quoteHide quote "Revoemag" wrote: > I have a very simple WebForm that has 3 Web Controls: 1 TextBox (TextBox1) > and 2 Buttons (Button1 & Button2). > > Button1 checks if the TextBox is Visible (or Enabled) and sets it to False > (or True in the opposite case). Button2 does absolutely nothing. > > If I set EnableViewState=False on the TextBox, I am no longer able to > control the .Visible or .Enabled properties. Button1 will set .Visible=False, > but will never set it to True again. Button2 (which does nothing) will bring > it back up (eg set it back to it's original state). > > With EnableViewState=True, it works as expected. Button1 toggles TextBox1, > Button2 does nothing. > > ------------ Code -------------- > <script runat="Server"> > > Sub Button1_Click(ByVal sender As System.Object, ByVal e as System.EventArgs) > TextBox1.Visible = Not (TextBox1.Visible) > End Sub > > Sub Button2_Click(ByVal sender As System.Object, ByVal e as System.EventArgs) > ' Do nothing > End Sub > </script> > <html> > <head><title>Form Test</title></head> > <body> > > <form Runat="Server"> > <asp:TextBox > ID="TextBox1" > EnableViewState="False" > Runat="Server" /><br /> > <asp:Button > ID="Button1" Text="Submit" > OnClick="Button1_Click" > Runat="Server" /> > <asp:Button > ID="Button2" > Text="Do Nothing" > OnClick="Button2_Click" > Runat="Server" /> > </form> > > </body> > </html> > ------------ Code -------------- > > This is a small example the issue that I use in a much more complex state. I > can write code to work around this (by explicitly setting Visible or Enabled > in every single button (eg Button2), but this seems like much more work than > necessary. > > Thank you in advance for any direction you can give.
Other interesting topics
Error: Content is not allowed between the opening and closing tags for element
Invalid FORMATETC structure (Exception from HRESULT: 0x80040064(DV_E_FORMATETC)) How to Catch exception for GridView control? Menu displays I-Beam cursor, not Hand GridViewUpdateEventArgs not including complete set of OldValues and NewValues DropDownList resets selectedIndex on postback object reference not set as an instance of an object Need Help: AccessDataSource and Assigning Variables for Data (ASP 2.0) Communicating between windows control and web page VS 2005 control with sql 2000 |
|||||||||||||||||||||||