Reputation: 245
I'm trying to pass post data from one page to the next but PreviousPage always equals null.
This is what I have in the original page (inside an updatepanel )
<asp:Button ID="mmGo" runat="server" Text="Merge" PostBackUrl="~/Default2.aspx?action=merge"/>
Then in the following page I have:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
...and in the .cs file:
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
string action = Request.QueryString["action"];
if (action == "merge")
{
UpdatePanel SourceControl = (UpdatePanel)PreviousPage.FindControl("UpdatePanel1");
HiddenField SourceTextBox = (HiddenField)SourceControl.FindControl("txtListIDs");
if (SourceTextBox != null)
{
Label1.Text = SourceTextBox.Value;
}
}
}
else
{
Label1.Text = "page is not cross page post back!";
}
}
Any ideas why the PreviousPage is always equal to null?
Upvotes: 4
Views: 10337
Reputation: 21
Yes... It's working... when you use button or linkbutton, use postbackurl, Don't use response.redirect. When you use postbackurl property you can have control, to control the previou page... for reference watch this video,,
http://www.youtube.com/watch?v=P1AqBtOYOMI
Difference between postbackurl and Response.Redirect ?
PostBackURL sends all the form data to the assigned page. Whereas when using Response.Redirect your sending the form data to your current page then moving your user to the assigned page
Upvotes: 2
Reputation: 887807
The PreviousPage
property returns the page that sent control to this page using Server.Transfer
.
If the current page is being rendered as a result of a direct request (not a transfer or cross-post from another page), the PreviousPage property contains null.
Upvotes: 6