Viewstate (maybe) issue with dynamic controls.
-
A bit of background before my problem: We're doing a security overhaul of our internal applications. We've decided that most pages will have 3 forms of security: read-only, partial input, and full control. The read-only and full controls portions are fairly self-explanatory. The partial input version of the page is controlled by the security roles we setup for the various users. One person may have the ability to edit a particular field, while another doesn't. We receive complaints about hard to read disabled drop down lists. As of right now we have two solutions: javascript that disables clicking on the control, or a custom control that changes the dropdown to a label when it is disabled. And now the problem: I'm working on this second option. I created a class that inherits from the DropDown class and created a new property called ChangeToLabel. Code follows:
Public Class DropDownDisable Inherits DropDownList Dim lbl As New Label Public Property ChangeToLabel() As Boolean Get Dim s As Boolean = CBool(ViewState("ChangeToLabel")) Return s End Get Set(ByVal value As Boolean) If value = False Then Me.Visible = True 'Me.Enabled = True lbl.Visible = False Else 'lbl.Style.ToString = Me.Style.ToString lbl.CssClass = Me.CssClass lbl.Width = Me.Width lbl.Height = Me.Height lbl.Visible = True lbl.Text = MyBase.SelectedItem.Text lbl.ID = Me.ID & "_disabled" lbl.BorderColor = Color.FromKnownColor(KnownColor.InactiveBorder) lbl.CopyBaseAttributes(Me) lbl.Enabled = True lbl.TabIndex = -1 Me.Visible = False Me.Parent.Controls.Add(lbl) End If End Set End Property End Class
The problem occurs when the page containing this control posts back. The newly created labels are getting lost. The even stranger problem is that not every label is disappearing. So far, all of the controls that disappear are in a third-party MultiPage control (we use ComponentArt). We run the security methods on every postback, so I'm assuming the labels are on the page in the appropriate places, and that they're just losing their text values. Thanks for any help you can give me. Tom -
A bit of background before my problem: We're doing a security overhaul of our internal applications. We've decided that most pages will have 3 forms of security: read-only, partial input, and full control. The read-only and full controls portions are fairly self-explanatory. The partial input version of the page is controlled by the security roles we setup for the various users. One person may have the ability to edit a particular field, while another doesn't. We receive complaints about hard to read disabled drop down lists. As of right now we have two solutions: javascript that disables clicking on the control, or a custom control that changes the dropdown to a label when it is disabled. And now the problem: I'm working on this second option. I created a class that inherits from the DropDown class and created a new property called ChangeToLabel. Code follows:
Public Class DropDownDisable Inherits DropDownList Dim lbl As New Label Public Property ChangeToLabel() As Boolean Get Dim s As Boolean = CBool(ViewState("ChangeToLabel")) Return s End Get Set(ByVal value As Boolean) If value = False Then Me.Visible = True 'Me.Enabled = True lbl.Visible = False Else 'lbl.Style.ToString = Me.Style.ToString lbl.CssClass = Me.CssClass lbl.Width = Me.Width lbl.Height = Me.Height lbl.Visible = True lbl.Text = MyBase.SelectedItem.Text lbl.ID = Me.ID & "_disabled" lbl.BorderColor = Color.FromKnownColor(KnownColor.InactiveBorder) lbl.CopyBaseAttributes(Me) lbl.Enabled = True lbl.TabIndex = -1 Me.Visible = False Me.Parent.Controls.Add(lbl) End If End Set End Property End Class
The problem occurs when the page containing this control posts back. The newly created labels are getting lost. The even stranger problem is that not every label is disappearing. So far, all of the controls that disappear are in a third-party MultiPage control (we use ComponentArt). We run the security methods on every postback, so I'm assuming the labels are on the page in the appropriate places, and that they're just losing their text values. Thanks for any help you can give me. TomHave you tried setting breakpoints to ensure they are created on a postback ? If it only happens in a third party control, have you asked them ? Their control could be doing something that only they can help you with.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
A bit of background before my problem: We're doing a security overhaul of our internal applications. We've decided that most pages will have 3 forms of security: read-only, partial input, and full control. The read-only and full controls portions are fairly self-explanatory. The partial input version of the page is controlled by the security roles we setup for the various users. One person may have the ability to edit a particular field, while another doesn't. We receive complaints about hard to read disabled drop down lists. As of right now we have two solutions: javascript that disables clicking on the control, or a custom control that changes the dropdown to a label when it is disabled. And now the problem: I'm working on this second option. I created a class that inherits from the DropDown class and created a new property called ChangeToLabel. Code follows:
Public Class DropDownDisable Inherits DropDownList Dim lbl As New Label Public Property ChangeToLabel() As Boolean Get Dim s As Boolean = CBool(ViewState("ChangeToLabel")) Return s End Get Set(ByVal value As Boolean) If value = False Then Me.Visible = True 'Me.Enabled = True lbl.Visible = False Else 'lbl.Style.ToString = Me.Style.ToString lbl.CssClass = Me.CssClass lbl.Width = Me.Width lbl.Height = Me.Height lbl.Visible = True lbl.Text = MyBase.SelectedItem.Text lbl.ID = Me.ID & "_disabled" lbl.BorderColor = Color.FromKnownColor(KnownColor.InactiveBorder) lbl.CopyBaseAttributes(Me) lbl.Enabled = True lbl.TabIndex = -1 Me.Visible = False Me.Parent.Controls.Add(lbl) End If End Set End Property End Class
The problem occurs when the page containing this control posts back. The newly created labels are getting lost. The even stranger problem is that not every label is disappearing. So far, all of the controls that disappear are in a third-party MultiPage control (we use ComponentArt). We run the security methods on every postback, so I'm assuming the labels are on the page in the appropriate places, and that they're just losing their text values. Thanks for any help you can give me. TomWell, my problem was my own dumb fault. As it turned out, I was doing things in the wrong order. I was creating a new label every time the control was built, instead of only creating a new label when the property was called. Now everything works great. Huzzah!! :-D