|
-
Feb 26th, 2004, 03:57 PM
#1
Thread Starter
Frenzied Member
Get a value from another page
How can you retrieve a value from one page to another?
For example if you have Webform1 and Webform2 in the Namespace WebApplication1 I would like to do this:
WebForm1.aspx
Code:
.
.
.
public class WebForm1 : System.Web.UI.Page
{
// give public access
public System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
.
.
.
WebForm2.aspx
Code:
.
.
.
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
private void Page_Load(object sender, System.EventArgs e)
{
TextBox1.Text = WebForm1.TextBox1.Text;
// Put user code to initialize the page here
}
.
.
.
The error is:
An object reference is required for the nonstatic field, method, or property 'WebApplication1.WebForm1.TextBox1'
Last edited by wey97; Nov 10th, 2004 at 09:50 AM.
-
Feb 26th, 2004, 05:59 PM
#2
PowerPoster
You can do this many ways.
1. Querystring. "WebForm2.aspx?MyText=testtext"
2. Server.Transfer (I haven't done this, but I think you can do this.)
3. Session variable. Before you leave page 1, set a session variable:
Session("MyValue") = text1.text
In page 2, get the value:
text2.text = Session("MyValue")
-
Feb 26th, 2004, 10:54 PM
#3
Frenzied Member
For Server.Transfer, you would allow the form to submit and in the submit button click event you would put this code
VB Code:
Server.Transfer("nextPage.aspx", True)
'True means maintain the state of the form,
'so the form elements can be requested from the nextPage.aspx page.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Feb 27th, 2004, 11:58 AM
#4
PowerPoster
You can cast the Handler Property to get a ref back to the transfering page and access any public members that way
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|