Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 50761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:38:38+00:00 2026-05-10T16:38:38+00:00

I’m looking for ideas and opinions here, not a real answer, I guess… Back

  • 0

I’m looking for ideas and opinions here, not a ‘real answer’, I guess…

Back in the old VB6 days, there was this property called ‘Tag’ in all controls, that was a useful way to store custom information related to a control. Every single control had it, and all was bliss…

Now, in .Net (at least for WebForms), it’s not there anymore…

Does anyone have a good replacement for that?

I find this problem very often, where I have different functions that run at different times in the lifecycle, and they do stuff with my controls, and I want to keep them as separate as they are, but one should pass information to the other about specific controls.

I can think of a million alternatives (starting with a module-level dictionary, obviously), but none as clean as the good ol’ Tag.

(NOTE: I know I can subclass ALL the controls and use my version instead. I’d rather not)

Any suggestions? How do you solve this normally? Any ideas on why they removed this i the first place?

EDIT: I’m looking for something Intra-Request, not Inter-Request. I don’t need this information to still be there on a PostBack. This is between the _Load and the _PreRender methods, for example.

EDIT2: I DO know my ASp.Net and I do know the difference between the desktop and the web, guys!. I ‘m just trying to use the abstraction that .Net gives me to the maximum. I understand the tradeoffs, believe me, and please answer assuming that I do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:38:38+00:00Added an answer on May 10, 2026 at 4:38 pm

    No, there’s no direct equivalent, but if you’re using v3.5 of the Framework, you can add this functionality quite easily using an extension method. For example:

    Imports System.Runtime.CompilerServices  Public Module Extensions   <Extension()> _   Public Sub SetTag(ByVal ctl As Control, ByVal tagValue As String)     If SessionTagDictionary.ContainsKey(TagName(ctl)) Then         SessionTagDictionary(TagName(ctl)) = tagValue     Else         SessionTagDictionary.Add(TagName(ctl), tagValue)     End If   End Sub    <Extension()> _   Public Function GetTag(ByVal ctl As Control) As String     If SessionTagDictionary.ContainsKey(TagName(ctl)) Then         Return SessionTagDictionary(TagName(ctl))     Else         Return String.Empty     End If   End Function    Private Function TagName(ByVal ctl As Control) As String     Return ctl.Page.ClientID & '.' & ctl.ClientID   End Function    Private Function SessionTagDictionary() As Dictionary(Of String, String)     If HttpContext.Current.Session('TagDictionary') Is Nothing Then         SessionTagDictionary = New Dictionary(Of String, String)         HttpContext.Current.Session('TagDictionary') = SessionTagDictionary     Else         SessionTagDictionary = DirectCast(HttpContext.Current.Session('TagDictionary'), _            Dictionary(Of String, String))     End If   End Function End Module 

    Then, in your ASP.NET pages, first bring your extensions into scope, e.g:

    Imports WebApplication1.Extensions 

    …and then use it your controls as desired:

    TextBox1.SetTag('Test')  Label1.Text = TextBox1.GetTag 

    LATER EDIT: and if you really, really don’t want to store your tags in the Session object, it’s possible to stuff them into your Viewstate instead. This will of course mean that your tags will be exposed in the page markup sent to the user (albeit in obfuscated form), and, unfortunately, that some reflection-fu is required, since the ViewState property of a Page is marked as ‘protected’ for some reason.

    So, this code should pretty much be considered for entertainment purposes only, unless you actually like to raise eyebrows during code reviews:

    <Extension()> _   Public Sub SetTag(ByVal ctl As Control, ByVal tagValue As String)     ViewState.Add(ctl.ID & '_Tag', tagValue)   End Sub  <Extension()> _   Public Function GetTag(ByVal ctl As Control) As String     Return ViewState(ctl.ID & '_Tag')   End Function  Private Function ViewState() As Web.UI.StateBag     Return HttpContext.Current.Handler.GetType.InvokeMember('ViewState', _                 Reflection.BindingFlags.GetProperty + _                 Reflection.BindingFlags.Instance + _                 Reflection.BindingFlags.NonPublic, _                 Nothing, HttpContext.Current.CurrentHandler, Nothing) End Function 

    FINAL EDIT (I promise…). And here’s a way to get rid of the reflection: first, create a new class to expose the ViewState property with a usable protection level, then change your Code-Behind (.aspx.vb) classes to inherit that instead of Web.UI.Page, e.g.:

    Public Class PageEx   Inherits System.Web.UI.Page    Friend ReadOnly Property ViewStateEx() As Web.UI.StateBag     Get         Return MyBase.ViewState     End Get   End Property End Class 

    Now, in your extensions module, you can access this newly defined property as:

    Private Function ViewState() As Web.UI.StateBag   Return DirectCast(HttpContext.Current.Handler, PageEx).ViewStateEx End Function 

    Still a bit of a hack, but much more acceptable than using reflection…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.