Reputation: 98740
I have two web form. example: a.aspx and b.aspx
In a.aspx i have a textbox with ID="Textbox1"
.
In b.aspx, i have a label with ID="Label1"
I want when i open b.aspx, Label1.text = Textbox1.Text
..
but when i write in b.aspx Page_Load function, intellisense doesn't know Textbox1
.
How can i do that?
Upvotes: 0
Views: 129
Reputation: 48583
When a user requests an .aspx, ASP.NET creates a new instance of your Page
class (the web form), processes it, then sends the resulting HTML to the user. Finally it destroys the page instance.
When you click a button on an ASP.NET page, you "post back" to the same URL (that is, you go from a.aspx
back to a.aspx
). Next, ASP.NET performs some magic: it maps values that users entered into form elements to controls on your page like Textbox1
.
To share values across pages, you need to use one of the following mechanisms:
Post directly to page b
. For the idiomatic ASP.NET way of doing this, see Cross-Page Posting in ASP.NET Web Pages.
Include the data in the URL itself, for example, by using a querystring:
http://www.mysite.com/b.aspx?contents=foo
Save the data in a session variable (or a cookie). This isn't a good idea unless the value is really scoped to the user's session (e.g., setting a time zone). Additionally, if scalability is important, you need to take greater care with session.
Save the data in a database, then retrieve it when building other pages.
Upvotes: 3
Reputation: 3618
You can always use Masterpages, and expose a public property on the masterpage. Have this property write to the viewstate of the page, and since it's public, pageA can write the value, and pageB can read the value.
Upvotes: -1
Reputation: 10134
save the value in session. this way users can type large amounts of text and it wont make the URL look ugly. also there is a limit to the length allowed for a URL.
use c# code such as this:
// create a new Session variable to store the users name
Session ( 'SomeText' ) = 'James';
// display the name in any page on your site
Out ( 'Your value is ' + Session ( 'SomeText' ) );
Upvotes: -1
Reputation: 15630
It can be done in many ways. Here i am telling two simple and easy methods 1. U can send the values as a parameter in the url if u r going to b.aspx by click a button,link button etc. U can add it like this
Response.Redirect("b.aspx?val="+text1.Text);
U can able to get the value by using
String txt=Request.QueryString["val"];
You can use session variables.So if u r using session variables the value can be acessed from any page in ur website{aspx}.
Session["val"]=textBox1.Text; //1st page Label1.Text=Session["val"].ToString();//2nd page
Hope u try this one
Upvotes: 0
Reputation: 945
most likely you have some action, like a button click on a.aspx that takes you to b.aspx, right? In the function for that button click, you would add the contents of the textbox to the querystring and redirect to b.aspx.
response.redirect("b.aspx?contents=" + Textbox1.text);
and then in b.aspx, in page_load, you would do:
Label1.text = request("contents");
Is that what you're asking? If you don't see it in intellisense, you might just need to close and reopen the page so that it will sync with the designer file.
Upvotes: 0