troubleshooting Question

How do I define a global/public variable in

Avatar of tangteng78
tangteng78Flag for Malaysia asked on
ASP.NETVisual Basic.NET
3 Comments1 Solution1056 ViewsLast Modified:
I have a public variable which i want it to be updated when user access the page first time, and i use "If Not Page.IsPostBack" to set it. This works fine.

However, i still want to retain this variabe on postback,,,,how can i do it? The public variable always reverted to it's default value that i set during declaration on postback.

See code below for the details.
Partial Class _Default
    Inherits System.Web.UI.Page
    Public strTest As String = "This is default setting"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            strTest = "First time login"
            Response.Write(strTest)   'I can NOT get the variable to be updated with "First time login" on postback
        End If
    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros