ASP.NET back and back button

Sorry if this turns out to be a hoax. I can’t find anything that exactly resembles my problem.

I have an asp: label in the form. On sending the postaback button, I do a server side check. If this fails, I set the label to a text value.

If I supply valid information and resubmit the send request, I set the label as a void as part of the submit click and it will postback and show a new page.

If I click the back button, it will display the correct information in the form and label of the error.

When you click submit again, the label text property is empty, although the text is clearly displayed on the screen.

I expect the label to be blank (not actually visible), since I set it to blank before I performed any actions.

I tried both the Text property and the Visible property, but with the same result.

Are you ready? GO ...

+4
source share
2 answers

You tried:

protected void Page_Load(object sender, EventArgs e) { lblMessage.Visible = false; } 

Each time your page loads, your message will be invisible. Therefore, when you check on the server, you can set the label text and set the Visibility = true value.

0
source

"If I click the" Back "button, it will display the correct information in the AND form of the error label: no problem with this; it shows you the state of the page at the time you posted it.

If you do not want your Label message to keep it visible or text, the markup should be:

 <asp:label id='myMsgLbl' runat='server' enableviewstate='false' visible='false/>' 

- change

As far as I know, the behavior with the back button looks as expected.

Maybe you should look for solutions to turn off the back button,

or disable caching of your form (but I think this solution will be worse than your first problem)

  private void Page_Load(object sender, System.EventArgs e) { Response.CacheControl = "no-cache"; Response.AddHeader("Pragma", "no-cache"); Response.Expires = -1; Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); 
0
source

Source: https://habr.com/ru/post/1403486/


All Articles