Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now