Runtime only constructor code
-
Hi all, I have a new class derived from WebControl. I need to add my own code to the constructor. However, I do not want this to be run at design time as it needs to access session data which will obviously not exist. How can I prevent this code from running at designtime? I have tried
if (!this.Site.DesignMode) etc...
but this.Site is null so that doesn't work. I have tried implementing IComponent but that makes no difference. Anyone have any suggestions??? Thanks in advance, Simon. -
Hi all, I have a new class derived from WebControl. I need to add my own code to the constructor. However, I do not want this to be run at design time as it needs to access session data which will obviously not exist. How can I prevent this code from running at designtime? I have tried
if (!this.Site.DesignMode) etc...
but this.Site is null so that doesn't work. I have tried implementing IComponent but that makes no difference. Anyone have any suggestions??? Thanks in advance, Simon.I hope I understand what you want correctly - If you have the appropriate properties, you can use data binding to your session data to dictate behaviour at runtime. For example, I needed to store a "tag" with a text box over post-backs, so I derived a class from TextBox (which is derived from WebControl), added a property like so in the .vb:
<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Tag]() As String Get Return Viewstate.Item("tag") End Get Set(ByVal Value As String) Viewstate.Item("tag") = Value End Set End Property
and in the aspx, I can databind that property like so:<cc1:mytextbox tag='<%# DataBinding code here %>' runat="server">
When you render the control, you can use the information in the property to dictate what it looks like. YMMV, HTH -- Ian Darling