Last post Feb 08, 2012 10:15 AM by Qi Wu - MSFT
Feb 06, 2012 08:33 AM|achuthan1988|LINK
I have two web pages 1) Source.aspx 2) Target.aspx
In the source.aspx page i have two textboxes to enter name and age. There is a submit button in the page. On clicking the submit button i am redirected to Target.aspx. In the Target.aspx page the following should be displayed. Let us suppose that the entered
name was john and the age entered was 19.
Hello Mr john. Your age is 19.
The words john and 19(in bold ) should be in color. The code in the Target.aspx should be in the source page and there should be no code in Target.aspx.cs
Feb 06, 2012 08:41 AM|sudhalaksh|LINK
Basically you want to pass data from one page to another page...
For that you can use mulitple approaches..
you can use sessions, cookies, query strings, etc.., Use any one of the approach and get the value in the other pages and use
Response.write() and print the values..
For further information please follow the below mentioned URL..
Feb 06, 2012 09:20 AM|achuthan1988|LINK
i know query strings but what i want is to write c# code within the html tags
Feb 06, 2012 09:28 AM|Ramesh T|LINK
Load them into Session and access in the target page as follow
<asp:Label runat="server" Text = "Hello Mr." + '<%:Session["name"]%>' + ". Your age is " + '<%:Session["age"]%>' + "." ></asp:Label> // if 4.0
<asp:Label runat="server" Text = "Hello Mr." + '<%=Server.HtmlEncode(Session["name"])%>' + ". Your age is " + '<%=Server.HtmlEncode(Session["age"])%>' + "." ></asp:Label> // if < 4.0
Feb 06, 2012 10:43 AM|achuthan1988|LINK
According to you i must initalize Textbox1.text=name and Textbox2.text= age .What i want is to somehow directly write Textbox1.text within the HTML code rather than using sessions..BTW i dont know sessions yet ...
Feb 08, 2012 10:15 AM|Qi Wu - MSFT|LINK
I use the cross-page posting in the below code.
The code in the source page.
<asp:TextBox ID="name" runat="server"></asp:TextBox> <asp:TextBox ID="age" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/Target.aspx" />
The code in the target page.
<% TextBox txtName = PreviousPage.FindControl("name") as TextBox ;
TextBox txtAge = PreviousPage.FindControl("age") as TextBox;
Response.Write("Hello,Mr "+txtName.Text+". Your age is:"+txtAge.Text);
And the session is very important in asp.net. You can learn it in the below link.