开发者

How to clear form on postback?

开发者 https://www.devze.com 2023-02-20 03:46 出处:网络
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 tha

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消