How can I clear all textboxes / uncheck checkboxes in my asp.net page wit开发者_运维问答hout doing a form submit (don't want to trigger validation controls)?
There's a simple HTML tag for that: <input type="reset" value="Clear" />
Make sure that any controls you want to clear are in the same form as the reset button.
foreach (var control in this.Controls)
{
if (control is TextBox)
{
((TextBox)control).Text = "";
}
if (control is CheckBox)
{
((CheckBox)control).Checked = false;
}
}
And here's a recursive version if you want to visit all controls..
Additionally, you can simply reload the page.
Response.Redirect("thispage.aspx");
Please try if this works:
function reset(){
document.forms[0].reset();return false;}
Call this javascript function upon client click event of a button. or add it as attribute:
ResetButton.Attributes.Add("onClick", "document.forms[0].reset();return false;");
HTH
精彩评论