Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

12 Experts available now in Live!

Get 1:1 Help Now