I am very new to ASP.NET. I just learned what postbacks are and I am trying to handle them, however, I would like to know if there is a way to "reset" the page. As in go to the original state of the page, before any postbacks were handled.
This will clear out any text boxes, check boxes, etc. In effect clearing any and all cache. Make it look like the user just opened the page fresh for the first time. Would like it to be a button called "reset" or "Start over".开发者_StackOverflow社区
Once you're done with your data, I would simply suggest doing a Response.Redirect("~/Example.aspx")
to the same page. That way you're not passing the ViewState back to the page.
Example.aspx
<asp:Button id="Reset" Text="Reset" runat="server" OnClick="Reset_Click" />
Example.aspx.cs
protected void Reset_Click(object sender, EventArgs e) {
Session["ViewState"] = null;
Response.Redirect("~/Example.aspx");
}
In the OnClick handler of the button, you could do a Response.Redirect
to the same page.
You can use the HTML input element with a type="reset":
<input type="reset" value="Reset" />
<asp:Button ID="Reset" runat="server" Text="Reset" align="center"
onclick="Reset_Click" />
protected void Reset_Click(object sender, EventArgs e)
{
Session["ViewState"] = null;
Response.Redirect("~/Form.aspx");
}
精彩评论