views:

1190

answers:

3

I have a textbox and a button on the ascx page.

After entering text i click on the button where it will post to the database and clear the textbox.

After positing, if i refresh the web page it is going to the button click method and posting the old text to the database. how can i clear the textbox value from the view state.

i have set the enableviewstate of the textbox to false. But still it is not working. Please let me know. Thanks

+1  A: 
protected void Button_Click(object sender, EventArgs e)
{
   var txt=textBox1.Text;
   textBox1.Text="";//Set it to empty

   // do other stuff
   ............ 
   ............
}
TheVillageIdiot
it's recommend to use string.Empty instead of ""
Cédric Boivin
This is what i tried. but it didn't work.
vamsivanka
@Cedric Boivin who recommended and why?
TheVillageIdiot
@vamsivanka you are simply refreshing on which browser sends previous request to the server again. try pressing CTRL+F5 and it will not do it. To solve this I suggest you redirect page to itself using Response.Redirect method like: **Response.Redirect("URL OF THIS PAGE",true);** If anybody know better method please let me know :)
TheVillageIdiot
A: 

In your click event if you set the textbox.Text property to strig.empty it's not work ?

Cédric Boivin
After posting to the db i have set textbox.text = string.empty.when i refresh the page, it has the old value again. Don't know why..
vamsivanka
This should have been a comment, not an answer.
Cory Larson
A: 

After you save your data with the click button you can set the textbox.text = ""

EDIT: After your comment that textbox.text = "" is not working....

When you hit the refresh it sounds like it is resubmitting your work again. Try just reloading the page by browsing to your page again.

Also be sure to check that you aren't saving your data on every postback but just on the button click event.

Do you have any code in your page load event?

klabranche
tried it. its still have the old value.
vamsivanka