Hi,
I tried out this cross page post back to understand the concept but it doesn't give me anything on the 2nd page. Hope someone can tell me what went wrong with my code. Tks.
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="hiddenfieldtest.WebForm1" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Cross Page Postback Example in asp.net</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td><b>Enter UserName:</b></td>
- <td><asp:TextBox ID="txtUserName" runat="server"/></td>
- </tr>
- <tr>
- <td><b>Enter Location:</b></td>
- <td><asp:TextBox ID="txtLocation" runat="server"/></td>
- </tr>
- <tr>
- <td></td>
- <td><asp:Button ID="btnPostback" Text="Postback" runat="server" PostBackUrl="~/WebForm2.aspx" /> </td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="hiddenfieldtest.WebForm2" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <b><u>WebForm2.aspx Page</u></b><br /><br />
- <label id="lblName" runat="server" /><br /><br />
- <label id="lblLocation" runat="server" />
- </div>
- </form>
- </body>
- </html>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
-
- namespace hiddenfieldtest
- {
- public partial class WebForm2 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
- {
- TextBox txtName = (TextBox)PreviousPage.FindControl("txtUserName");
- TextBox txtLocation = (TextBox)PreviousPage.FindControl("txtLocation");
- lblName.InnerText = "Welcome to WebForm2.aspx page " + txtName.Text;
- lblLocation.InnerText = "Your Location: " + txtLocation.Text;
- }
- else
- {
- Response.Redirect("WebForm1.aspx");
- }
- }
- }
- }