开发者

In ASP.NET, how can you "reset" and go back to the original state, pre postbacks?

开发者 https://www.devze.com 2023-04-06 07:10 出处:网络
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 stat

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");
    }
0

精彩评论

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