Why is this code causing exception

T

Tony Johansson

Hello!

First I added two new aspx pages to the solution with names Default.aspx and
Result.aspx.
I then added two web server buttons to each aspx page. I set the property
PostBackUrl for the Button in the Default.aspx
to Result.aspx.
When I start the Default and click on the Button this Page_Load in the
Result class is called
and this PreviousPage.IsValid return true so so far is everything correct.

But now if I click the Button when the Result page is being displayed this
PreviousPage.IsValid throws an exception saying
NullReferenceException was unhandled by user code.
The object reference has not been set to an instance of the object.
I can't understand why I get this exception. I mean that there must exist a
PreviousPage what this Result.aspx was called the first time.

public partial class Result : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage.IsValid)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{

}
}

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top