I'm working with CrossPagePostback using PostBackURL and I'm running into sporadic errors revolving around PrevousPage.IsValid.
The source (source.aspx) has a LinkButton with an OnCommand event, a PostBackURL of "target.aspx" and CausesValidation="true". The target (target.aspx) page checks for PreviousPage != null in Page_Load and then attempts to access PreviousPage.IsValid to validate that the source pages inputs were valid.
99 times out of 100 this works fine, but we're getting sporadic errors where PerviousPage.IsValid throws an exception saying that IsValid cannot be accessed until Page.Validate has been called.
My understanding is that when I'm accessing PreviousPage from "target.aspx", it creates a new instance of "source.aspx" and starts running through the life cycle, handling events, etc, up until Load_Complete. Is this correct?
If this is the case, if the PreviousPage ran into any type of error during processing it's events, is it possible that it would not return a null instance, but still not process the validation events? Or is there any other reason why PreviousPage would NOT BE NULL, but Page.IsValid would toss an error - when the only way for the "source.aspx" page to transfer control to "target.aspx" is through a LinkButton which forces validation?
This isn't the full page, but here is the idea. Please let me know if I need to explain more.
<form id="form1" runat="server">
<asp:TextBox id="txtUsername" runat="server" />
<asp:RequiredFieldValidator id="reqUsername" runat="server" ControlToValidate="txtUsername" Text="*" />
<asp:LinkButton id="lbSearch" runat="server" PostBackUrl="~/target.aspx" OnCommand="ProcessSearch" />
</form>
public class Source : Page
{
protected void Page_Load()
{
if(!IsPostBack)
{
// DO random database stuff or other controls on page
}
}
protected void ProcessSearch(object sender, CommandEventArgs e)
{
// DO search process stuff
}
}
public class Target : Page
{
protected void Page_Load()
{
if(PreviousPage != null)
{
if(PreviousPage.IsValid) //sometimes throws and exception
{
// DO STUFF
}
}
}
}