Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Runtime only constructor code

Runtime only constructor code

Scheduled Pinned Locked Moved ASP.NET
questiondesign
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Simon_uk
    wrote on last edited by
    #1

    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 1 Reply Last reply
    0
    • S Simon_uk

      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 Offline
      I Offline
      Ian Darling
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups