Hi:
I get an (object reference not set to an instance of an object) error when I use a PostBackUrl as a method to pass data between pages. Please see following code. The code in red is highlighted in the error. This error occurs infrequently and seemingly randomly.
page 1------
codebehind for page 2------
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string previouslogin;
previouslogin = ((TextBox)PreviousPage.FindControl("logintxt")).Text;
.
.
.
.
.
.
}
}
}
PostBackUrl troubles
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Ankit NandekarRank #703 · 3.4K reputationPosted Apr 20, 2011, 6:52 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Apr 20, 2011, 12:58 PM EDT
if (Page.PreviousPage != null) {
DropDownList ddl = (DropDownList)Page.PreviousPage.FindControl("ddl1");
if (ddl != null) {
lbl4.Text = ddl.SelectedItem.Text;
lbl4.ForeColor = System.Drawing.Color.FromName(lbl4.Text); } }
Craig Davis37 reputationPosted Apr 20, 2011, 6:30 PM EDT