Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form values not clearing.

Status
Not open for further replies.

Pandyon

Programmer
Feb 21, 2001
38
US
I have a .NET form using C# that I use for both editing a table and adding a new record. When editing, it grabs data from a record and fills the form text boxes with the info, and shows an "Edit" button. Click on "Edit" and it works fine. At the top, I have a "New" button. This is supposed to clear out the form of all values, and show a new button called "Add". I'm using a foreach loop to clear the text box controls, and on the screen the boxes do clear.

But regardless of when I type in new data and click "Add", it inserts a new record with the most previous record that had been pulled up into that form for an edit. So the "clearing" isn't working somehow. And it's no longer seeing what I'm putting into the text boxes.

Any help appreciated.

Mark
 
When you click the "New" button, instead of calling your code, have the page redirect to itself, without any querystrings. This should clear the stored viewstate and form values collection.
 
That won't really work. The page load by default only includes a list of existing members in a dropdown list, with an Edit button and a New button. Choosing either a member from the list and clicking Edit, or just clicking New makes the form appear.

So if I redirect, then it takes me back to that page, where I have to click "New" a second time for the form to appear.

I suppose I could have the form appear by default, but I was trying something a bit more elegant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top