Solved

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

Posted on 2006-07-24
3
271 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

705 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