ASP.net LinkButton and global variables

Hi

I try to assign a value to a global variable by using the click event of a LinkButton
shown below
The PostBackURL is "~/Daily.aspx"
and I am trying to check that the value assigned to the variable on the click event
comes through, but it doesn't

    Protected Sub LinkButtonL_Click(sender As Object, e As EventArgs) Handles LinkButtonL.Click
        LIFE_Category = "L"
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not IsPostBack Then

                MsgBox(LIFE_Category)
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

unknown_routineCommented:
This is a "Good" question.

The probelm is unlike winfrom webfrom global variables are not so global.

Every time from load event is fired all form level variables are reset to defalut values, in your case string is set to "".

To preserveyour form levle variable, just put in in a session variable:

 Protected Sub LinkButtonL_Click(sender As Object, e As EventArgs) Handles LinkButtonL.Click
        Session("LIFE_Category") = "L"
    End Sub

Open in new window



Then you can read it in page load:

If Not IsPostBack Then

                MsgBox(Session("LIFE_Category") 

Open in new window



Note: you could also put it in viewstate object:

 Viewstate("LIFE_Category") = "L"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Great answer. Thanks very much
0
unknown_routineCommented:
Your welcome! This was a very good question for E.E knowledgebase
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.