Craig Davis

Craig Davis

  • NA
  • 40
  • 0

PostBackUrl troubles

Apr 20 2011 10:26 AM
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------
<form id="form1" runat="server">
<<asp:Label ID="loginlbl" runat="server" Text="Login:"></asp:Label>
<asp:TextBox ID="logintxt" runat="server"></asp:TextBox><br />
<asp:Button ID="loginbutton" runat="server" PostBackUrl="page2.aspx" Text="Login" /><br />
</form>

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;
.
.
.
.
.
.
}
}
}

Answers (3)