Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My run mode as follows


Detailspage as follows

Empid 10001

Mobile 9784000002

Submit (Button)

When i give the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window in browser when i press back (<-) arrow it will go detailspage.aspx.

Then again when i enter wrong Empid and Mobile it shows the message in the label1 as "Your Data does not match".


Then user enter the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window, in browser when i press back (<-) arrow it will go Detailspage.aspx. in that detailspage.aspx previously shows the message in the label1
"Your Data does not match". that message to set visible false.




In submit button code as follows


protected void btnsubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString="Data Source=.\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True;"
string query = "select * from login where Empid= '" + txtempid.text + "' and mobile = '" + txtmobile.text + "'";
SqlCommand cmd = new SqlCommand(query,con);
con.open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
Datatable dt = new datatable();
da.Fill(dt);
if(dt.Rows.Count > 0)
{

Response.Redirect("Detailspage.aspx");
label.visible = false;
}

else
{
label1.text = "Your Data does not match";
}

}


But when i run the code the label1 is not visible false. when it redirects to Details.aspx page.

Please help me what is the mistake in my above code.

What I have tried:

When i give the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window in browser when i press back (<-) arrow it will go detailspage.aspx.

Then again when i enter wrong Empid and Mobile it shows the message in the label1 as "Your Data does not match".


Then user enter the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window, in browser when i press back (<-) arrow it will go Detailspage.aspx. in that detailspage.aspx previously shows the message in the label1
"Your Data does not match". that message to set visible false.
Posted
Updated 5-Sep-16 5:26am
Comments

1 solution

The code is working perfectly because when a postback occurs, the framework "remembers" the state of the page which is label visibility = true or false depending on the logic when button was clicked. So if your code is making it visible, clicking back button only re-loads the page as the user left it, it doesn't automagically execute any button clicks for the user.

This is the default function of any browser and .net.

if you want to make the user see a different label when they click back button then on submit in first place, set a session variable to identify the submit clicked.
then on page load check the session variable to see if the user clicked back button.
For example you could save the TimeStamp or datetime of when the user clicks on submit and check if it is in the past on page load.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900