Problem using variables from previous pages [ Asp.net + C# ]
I have been trying to get a variable to hold previous page content. I have been able to get this to work as long as I pass the CurrentUser and CurrentPass to a text box and then use that info from there. So, I've been hiding text boxes in my page to make this work. I don't understand why I can't just place these previous page variables into newly defined variables on this page.
I have tried a couple of different things but I keep getting the error message:
Error 1 An object reference is required for the nonstatic field, method, or property 'userpage.PreviousPage.get' C:\Inetpub\wwwroot\ThisTest\userpage.aspx.cs 15 30 C:\...\ThisTest\
The sample of one of my ideas:
static string crrntUsr = PreviousPage.CurrentUser.ToString();
static string crrntPss = PreviousPage.CurrentPass.ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Get the user name from the login page
crrntUsr = PreviousPage.CurrentUser;
//Get the password from the login page
crrntPss = PreviousPage.CurrentPass;
//Write out the usr and pass to textbox
//Label1.Text = PreviousPage.CurrentUser + PreviousPage.CurrentPass;
Label1.Text = crrntUsr + crrntPss;
//Label2.Text = PreviousPage.CurrentUser;
//Label3.Text = PreviousPage.CurrentPass;
while (reader.Read())
{
string usr = reader["UserName"].ToString();
usr = usr.TrimEnd();
string pss = reader["Password"].ToString();
pss = pss.TrimEnd();
if (Label2.Text == usr)
{
if (Label3.Text == pss)
Putting it directly into a text box and then going on with code using labels are fine. But I don't want to use hidden text boxes and labels, I was hoping someone could help me understand why I am not able to use variables to work with the previous page data.
My .aspx page has this directive:
<%@ PreviousPageType VirtualPath="login.aspx" %>
My previous pages .aspxcs has this code in it too:
public String CurrentUser
{
get
{
return userTxtbx.Text;
}
}
public String CurrentPass
{
get
{
return psswrdTxtbx.Text;
}
}
Thank you so much in advance.
Re: Problem using variables from previous pages [ Asp.net + C# ]
remove your 'static' variables. when you are pulling the variable from a dynamic page, it isn't static. In most cases static variable has be set before runtime in most cases. I am not sure if this applies to the page life cycle, but judging from other microsoft platforms I have worked on it is the same way.
Re: Problem using variables from previous pages [ Asp.net + C# ]
Okies, I've given that a shot. I still get the same message. Thank you.
Re: Problem using variables from previous pages [ Asp.net + C# ]
Label1.Text = PreviousPage.CurrentUser + PreviousPage.CurrentPass;
//Label1.Text = crrntUsr + crrntPss;
Label2.Text = PreviousPage.CurrentUser;
Label3.Text = PreviousPage.CurrentPass;
Re: Problem using variables from previous pages [ Asp.net + C# ]
What happens when you do a PreviousPage.FindControl() for the textbox in question, cast it, get its text property and then assign that to a variable?