Cross-Page PostBack error when posted from one folder to another
I'm getting the 'Object reference not set to an instance of an object.' error on PreviousPage after using PostBackUrl.
I created a simple test page to recreate the problem, however it worked fine, until I moved the source and destination pages into different folders. Is this the reason the PreviousPage object is null? how do I fix it?
Both the folders the source and destination pages are in are in the root directory of the website.
Source Page: /companies/test.aspx
<asp:Content runat="server" ID="Content" ContentPlaceHolderID="FullPage">
<asp:TextBox ID="Demo" runat="server"></asp:TextBox>
<asp:LinkButton ID="testlink" Text="test" runat="server" PostBackUrl="~/Documents/test2.aspx">
TESTING
</asp:LinkButton>
</asp:Content>
public string MyVariable
{
get
{
return Demo.Text;
}
}
D开发者_高级运维estination Page: /documents/test2.aspx
<%@ PreviousPageType VirtualPath="~/Companies/test.aspx" %>
<asp:Content runat="server" ID="Content" ContentPlaceHolderID="FullPage">
<asp:Label ID="output" runat="server" />
</asp:Content>
protected void Page_Load(object sender, EventArgs e)
{
string MyText = PreviousPage.MyVariable;
output.Text = MyText;
}
Solved: Problem was in the casing of the PostBackUrl and the actual Directory structure.
精彩评论