When I wrote "It worked as expected" I meant:
when I opened the page 7UserControlProperty.aspx in Internet Explorer, I saw the buttonPostback, the Label with a white backcolor, and the Textbox with a white backcolor and a width of 200px;
When I clicked the Postback button, I saw the Label with a yellow backcolor, and the Textbox with a yellow backcolor and a width of 400;
When I clicked the Postback button again, I saw the Label return to its original white backcolor, and the Textbox return to a white backcolor and a width of 200;
Each time I clicked the Postback button, the Label's backcolor and the Textbox's backcolor and length changed.
When I changed the code in the Page_Load event in ucLabelTextboxSeven.ascx.
vb
from "If TextBox1.BackColor = Drawing.Color.Yellow Then"
to "If ucpTextboxWidth = typeWidth.Longer Then",
then opening the page 7UserControlProperty.aspx in Internet Explorer behaved differently. Now, when I repeatedly click the Postback button, the Label's backcolor remains yellow and the Textbox's backcolor remains yellow and its width remains Longer (400px). That's what I meant by "not working" – shouldn't the page behave in the same way no matter which If-clause I use?.
As for debugging, I jumped to Chapter 18 and your description of setting a breakpoint. I set the breakpoint on the line "If Page.IsPostBack Then" and opened the page 7UserControlProperty.aspx in Internet Explorer by using the key F5. The page opens with ucpTextboxWidth = typeWidth.Shorter, as expected because the Textbox is initialized with this value in the page. When I clicked on buttonPostback and look at the breakpoint ucpTextboxWidth again equals typeWidth.Shorter and then, stepping through the Page_Load routine, I saw the ucpTextboxWidth change to Longer. After stepping through the rest of the Page_Load routine, IE displayed the Textbox with a width of 400px (Longer) and backcolor = yellow as expected. Clicking on buttonPostback a second time brought me back to the Page_Load rountine and ucpTextboxWidth should have been equal to typeWidth.Longer. But it was reset back to the Shorter value and therefore resulted in the Textbox's width being set to Longer again and again with each click of the Postback button.
I see the user control ucLabelTextboxSeven is initialized in the page 7UserControlProperty.aspx with ucpTextboxWidth="Shorter" and so, I assume, every Page_Load finds the user control property ucpTextboxWidth re-initialized with the Shorter value. On the other hand, the backcolor of the Textbox remains with the value that Page_Load set it to previously and so toggling works if TextBox1.backcolor is tested instead of ucpTextboxWidth.
So, I removed initializing ucpTextboxWidth="Shorter" from 7UserControlProperty.aspx:
Code:
<uc1:ucLabelTextboxSeven ID="ucLabelTextboxSeven1" runat="server" />
I added code to the Page_Load routine of ucLabelTextboxSeven.ascx.
vb to initialize ucpTextboxWidth the first time, before postback:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
If ucpTextboxWidth = typeWidth.Longer Then
ucpTextboxWidth = typeWidth.Shorter
Else : ucpTextboxWidth = typeWidth.Longer
End If
Else : ucpTextboxWidth = typeWidth.Shorter ' initial setting.
End If
Select Case ucpTextboxWidth
Case typeWidth.Shorter
TextBox1.Width = "200"
TextBox1.BackColor = Drawing.Color.White
Label1.BackColor = Drawing.Color.White
Case typeWidth.Longer
TextBox1.Width = "400"
TextBox1.BackColor = Drawing.Color.Yellow
Label1.BackColor = Drawing.Color.Yellow
End Select
End Sub
It still does not work! That is, repeated clicking of buttonPostback does not result in the toggling of the Textbox width and backcolor, i.e., once the Postback button is clicked, the Textbox width is Longer and the backcolor is yellow and the Textbox remains that way.
I again set the breakpoint to the first line of the Page_Load event and opened the page 7UserControlProperty.aspx in IE. I saw that even the very first time, before any postback, the user control property ucpTextboxWidth was already initialized to typeWidth="Shorter" before taking any steps through the routine. With every click of buttonPostback the Page_Load routine immediately begins with typeWidth="Shorter".
Thanks for your help.
Marshall