473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to refer to a variable on another webform

How to refer to a variable on another webform

Hi, I have a Webform1 with a public variable that is assigned a value before
my Webform2 is displayed. In the Page_Load procedure of Webform2 I want to
evaluate the value of the variable of Webform1.

Code on Webform1

Public MyVar1 As Integer

Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.ServerClick

MyVar1 = 1
Server.Transfer("Webform2.aspx")

End Sub
Code on Webform2

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Myvar2 As Integer
Myvar2 = (Myvar1 from Webform1... Any Ideas?)

End Sub

T I Rislaa

Nov 17 '05 #1
3 1536
You can't. Once the webform1 finishes execution, it ceases to exist.

You will have to store the value in session or pass it in the query string,
or place it elsewhere where both forms can access to it.

"Tor Inge Rislaa" <to*************@rislaa.no> wrote in message
news:e5**************@TK2MSFTNGP12.phx.gbl...
How to refer to a variable on another webform

Hi, I have a Webform1 with a public variable that is assigned a value before my Webform2 is displayed. In the Page_Load procedure of Webform2 I want to
evaluate the value of the variable of Webform1.

Code on Webform1

Public MyVar1 As Integer

Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.ServerClick

MyVar1 = 1
Server.Transfer("Webform2.aspx")

End Sub
Code on Webform2

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Myvar2 As Integer
Myvar2 = (Myvar1 from Webform1... Any Ideas?)

End Sub

T I Rislaa

Nov 17 '05 #2
Tap
Open the Visual Studio.NET help....and type in the
following in the address bar.....

ms-
help://MS.VSCC/MS.MSDNVS/vbcon/html/vbtskPassingValuesBetwe
enWebFormsPages.htm

It describes how to pass values in between web forms and
of course you can always use query strings too.

Thanks,

Tap
-----Original Message-----
How to refer to a variable on another webform

Hi, I have a Webform1 with a public variable that is assigned a value beforemy Webform2 is displayed. In the Page_Load procedure of Webform2 I want toevaluate the value of the variable of Webform1.

Code on Webform1

Public MyVar1 As Integer

Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.ServerClick

MyVar1 = 1
Server.Transfer("Webform2.aspx")

End Sub
Code on Webform2

Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load

Dim Myvar2 As Integer
Myvar2 = (Myvar1 from Webform1... Any Ideas?)

End Sub

T I Rislaa

.

Nov 17 '05 #3
That's not correct.

You can use server.transfer as your code is beginning to. The next step is
to recreate the first page on the second. You will need to do a CType on the
context object that is passed using server.transfer.

Dim Page1 As Page1 = CType(Context, Page1)

The important thing is that if you can arrive at a page2 from more pages
than page1 this code will error out if you try to make say, page3, into
page1.

I have some sample code in the code library on my website,
www.aboutfortunate.com for determining which page a context object came
from. Just search for: "get page name".

I hope this helps.

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Marina" <zl*******@nospam.hotmail.com> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
You can't. Once the webform1 finishes execution, it ceases to exist.

You will have to store the value in session or pass it in the query string, or place it elsewhere where both forms can access to it.

"Tor Inge Rislaa" <to*************@rislaa.no> wrote in message
news:e5**************@TK2MSFTNGP12.phx.gbl...
How to refer to a variable on another webform

Hi, I have a Webform1 with a public variable that is assigned a value

before
my Webform2 is displayed. In the Page_Load procedure of Webform2 I want to evaluate the value of the variable of Webform1.

Code on Webform1

Public MyVar1 As Integer

Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick

MyVar1 = 1
Server.Transfer("Webform2.aspx")

End Sub
Code on Webform2

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Myvar2 As Integer
Myvar2 = (Myvar1 from Webform1... Any Ideas?)

End Sub

T I Rislaa


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew | last post by:
Hi, Until now, I have used a single webform for my web app, and everything's been OK. Now, I've decided to create a main menu webform. So, I've got two webforms. Using Visual Studio .NET (with...
1
by: Epson Barnett | last post by:
Hi, I'm new to C# and I'd like to be able to reference a field of an object using a variable instead of literal text. In the PHP scripting language, you can create a variable: $var = "name";...
6
by: dave | last post by:
I have a webform with many checkboxes on it. I want the user to be able click on a button and the page be posted to another webform so that I can capture which checkboxes were selected. For all...
0
by: news_server.nc.rr.com | last post by:
How do i perform a databind on a web user control within a repeater or rather how can I access the datasource that is already bound? I have a web user control that displays a table of values (the...
1
by: Antoine | last post by:
I have a pretty quickish question about ASPX with codebehind. I have done an exhaustive search of the web so no go there. I was hoping to reach out for some help here. Anyway, I have a really...
3
by: Dean Slindee | last post by:
Would like to call the TabShow function on WebForm InOutHost from another WebForm in same project, but cannot figure out how to get a reference. Can this be done? In this statement: Call...
7
by: Max | last post by:
Please somebody can shed a light... How can I have a variable visible and modifiable, inside one and only webform? I mean , I d like to see that variable from all the Sub of that webform code,...
2
by: Luqman | last post by:
How can I open another WebForm in ASP.Net / VS 2005 without closing the Current Webform. I tried using Server.Transfer("Form2.Aspx",True) on Button_Click of Form1 but it close the current web...
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have start web form and when the user clicks a button (server.transfer) they are directed to the second webform. I was wondering if there is a way to create an instance of the first webform...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.