简体   繁体   中英

Clear text value of textbox asp.net?

Sorry if I did not explain well.

Create a website with ASP.NET C #, I have a page that I use to insert data into SQL Server, which has several TextBox controls where necessary to insert data is entered.

Everything works fine for the insertion of data in SQL, data are sent to a class to insert using a stored procedure to delete the content end of the TextBox controls using "TextBox.Text = string.Empty". Works excellent everything is erased. Check the Debug Mode and if you delete the contents of the TextBox controls.

But if you refresh the page the method that sends the data to the class to insert runs automatically; validations have to keep out if the controls are empty but overlooked. Reviewing the Debug Mode to see it again to refresh using the same data that was just deleted controls.

Why does that happen and how do I fix it.

Different things happen in different situations when you refresh the page.

If the page was created as a response to a post/postback, then the posted data will be sent to the server again to request the page. That means that the server code will react the same as when the page was first created, including for example saving the form data or getting new data from the database.

If you want to prevent the form data to be resent on a refresh, you can do a Response.Redirect when the server reacts to a form submission. That will make the browser do a GET request to fetch the page, so there will be no form data to repost.

Different browsers handle form data in a request slightly differently. Most browsers remember form data to some extent, so when you refresh the page some of the form data may be remembered by the browser, and will replace the values that the server put in the form fields.

If you refresh the page for testing, you can use ctrl+F5 to tell the browser to make a "clean refresh", ie get everything from the server instead of using data from the cache, and don't fill the form with saved data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM