Solved

set variable in Page_Load and then get the value in another sub

Posted on 2006-07-24
3
270 Views
Last Modified: 2008-03-17
Hi,

I do this to set a variable:
private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                   string strVar =Request.ServerVariables["HTTP_REFERER"];
                  
            }
How do I retrieve this variable in ibtnSubmit_Click?

0
Comment
Question by:FullWilliams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:proten
ID: 17168274
Define the variable before the page_load sub, you now can access it in all subs:

string strVar

private void Page_Load(object sender, System.EventArgs e)
          {
               // Put user code to initialize the page here
                string strVar =Request.ServerVariables["HTTP_REFERER"];
               
          }
0
 
LVL 33

Accepted Solution

by:
raterus earned 250 total points
ID: 17169096
I'm assuming these are not the same request, or else you could just pull from Request.ServerVariables in btnSubmit.

I'd add the property to viewstate (works just like the session, only it's page based), if you are accessing this across requests, proten's solution will not work.

0
 

Author Comment

by:FullWilliams
ID: 17175061
Thanks raterus.

viewstate and session both worked.  

Session["myvar"] = Request.ServerVariables["HTTP_REFERER"];
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question