How to clear form on postback?
Is there a simple way to clear the value of server controls on postback? I have tried ViewState.clear() and it开发者_C百科 doesn't do anything. The page I am working on inherits from a Masterpage that has viewstate enabled.
You can redirect back to the page.
Response.Redirect(pathToPage);
This is however an extra round-trip (response to the browser that will re-request the page).
Another option is to recurse through the controls hierarchy, clearing each control in turn.
You'll either have to redirect back to the same page or clear the controls manually.
You tried ClearChildViewState()
?
You can clear all controls in your form using this:
form1.Controls.Clear()
精彩评论