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 8227811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:15:13+00:00 2026-06-07T16:15:13+00:00

I am working on a website with .aspx pages and code behind in VB.Net.

  • 0

I am working on a website with .aspx pages and code behind in VB.Net. On a page I need a Public Shared variable like

Public Shared comments As String() = New String(2) {"", "", ""}

since I need the persistence of the value of “comments” through post backs of the page. At least I think having it Public Shared is the only way to keep the persistence, unless you guys tell me that I am wrong.

But on the other hand I don’t want other users who might be using the same page conflict their “comments” data with other users. How can I achieve this?

  • 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. Editorial Team
    Editorial Team
    2026-06-07T16:15:15+00:00Added an answer on June 7, 2026 at 4:15 pm

    It depends on the level of persistence you need.

    If you only need the comments to live on the page until the user has navigated away from it, use your page’s ViewState:

    Public Property Comments As String()
        Get
            If Me.ViewState("Comments") Is Nothing Then
                Me.ViewState("Comments") = New String(2) {"", "", ""}
            End If
            Return Me.ViewState("Comments")
        End Get
        Set(value As String())
            Me.ViewState("Comments") = value
        End Set
    End Property
    

    If you’d like the values to persist for the page between navigating away and newly landing on the page again (i.e. initial load rather than postback), use your Session state bag:

    Public Property Comments As String()
        Get
            If Me.Session("MyPage_Comments") Is Nothing Then
                Me.Session("MyPage_Comments") = New String(2) {"", "", ""}
            End If
            Return Me.Session("MyPage_Comments")
        End Get
        Set(value As String())
            Me.Session("MyPage_Comments") = value
        End Set
    End Property
    

    If you’d like this to persist even after the session is expired and the user returns later, you’d need to write to a backing store that would link the user to their comments such as a database, or–and I say this with much less enthusiasm–write out to something like an XML file, and then load the value on your initial page load in a statement such as:

     Public Sub PageLoad(sender As Object, e As EventArgs) Handles Me.Load
         If Not Me.IsPostBack
             ' Read the value from the backing store
         End If
     End Sub
    

    When using a backing store, however, I generally recommend using one of the data source controls along with a databound control such as a ListView or GridView to display the information.

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

Sidebar

Related Questions

I'm working on a C# updatable ASP.NET 2.0 precompiled website . Since the code-behind
I'm working with an asp.net website using C# in the background. I would like
I am working on a website hwere i need to introduce security for reasons,
I'm working on a website for a client and I would like a way
I've inherited some code that I need to debug. It isn't working at present.
I'm working on a web site where the new pages are ASP.NET and the
I'm working locally on an ASP.NET website under Windows 7, and I experience stange
I am working on a donations website. In my page, I have a textbox
I'm working on a web page (ASP.NET 4.0) and am just starting simple to
I am working on an ASP.NET 4.0 web forms project that uses page routing

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.