5

I have a site/portal created in ASP.net and VB.net.

I want to know how to reference variables between two asp pages, but not the pages themselves, I want to directly transfer data from the .aspx.vb bit of the page to another pages .aspx.vb file. Is that possible?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
mHo2
  • 103
  • 1
  • 2
  • 9
  • You could set a cookie, set a value in a shared resource (database), set a value in session, use a query string parameter when redirecting to the page. There are a lot of options for this, but none that allow you to just access values on the page itself. – Stefan H Jul 12 '12 at 15:14

4 Answers4

0

An easy way in asp.net/VB.net is to use session variables.

Session("myVariable") = "blah"

From another .aspx.vb page you can now use this value. Example:

Dim strTest as String = ""
strTest = Session("myVariable")

You can access this page on any of your .aspx pages for this session by referencing Session("myVariable")

Matt
  • 2,078
  • 2
  • 27
  • 40
  • So I could access this in one aspx.vb 'behind-page' vb form as a reference? I want to be able to set the value of a variable on one aspx.vb 'page' and only be able to update it and access the updated value from another aspx.vb 'page'. – mHo2 Jul 12 '12 at 15:36
  • You can set it on any page and update it from any aspx.vb page. – Matt Jul 13 '12 at 14:14
0

if it's Not sensitive data you can do something like this,

Original page: protected void Button1_Click(object sender, EventArgs e)

{
          string MyOccupation = "Software Developer";

          string url;
          url = "page2.aspx?occupation=" + MyOccupation;

          Response.Redirect(url);

}

Next Page: string RetrievedValue;protected void Page_Load(object sender, EventArgs e)

{

          this.TextBox1.Text = Request.QueryString["occupation"];
          RetrievedValue = this.TextBox1.Text;

}

taken from http://forums.asp.net/t/1223291.aspx

Eric Robinson
  • 2,025
  • 14
  • 22
0

Duplicate of How can I pass values from one form to another in Asp.net

Client side technology: Query String

Query String: For SEnding:

string name="abc"; Response.Redirect(" Page2.aspx?name= "+name);

For Getting: On Page2.aspx string name=Response.QueryString.GetValue(" name ");

Server Side Technology:Session

For Setting: Session["Name"] = "Abc";

For Getting: string str = Session["Name"].ToString();

In Session you can pass any object type.

Community
  • 1
  • 1
Waqar Janjua
  • 6,113
  • 2
  • 26
  • 36
0

Since nobody posted this, here is Microsoft's page about passing values between pages. It gives C# and VB examples: http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx

Emily
  • 444
  • 1
  • 3
  • 12