I am trying to pass the value of a variable from one page to another using cross page post-back using this code:
on page1:
<asp:TextBox ID="changepwd" runat="server"></asp:TextBox>
<asp:Button ID="ChangePassword" runat="server" Text="Change Password"
PostBackUrl="~/Page2.aspx" />
I have assigned its value at runtime from the database in the cs file as:
changepwd.Text = dataSet.Tables[0].Rows[0]["empPassword"].ToString();
On page 2: In page load event:
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
TextBox txt = (TextBox)PreviousPage.FindControl("changepwd");
TextBox1.Text = txt.Text;
}
}
but I don't get the value from the previous page. i am getting the value as null
.
On page1 I am getting the value correctly from the database but it is not being passed onto page 2. Can you please tell me why?