开发者

Link button to previous page

开发者 https://www.devze.com 2023-03-20 10:52 出处:网络
I am making an application in asp.net(c#,visual studio 2008). In this I make a page in which there is a \'proceed\' link button. on clickingthisbutton will go to the next page.on the next page there i

I am making an application in asp.net(c#,visual studio 2008). In this I make a page in which there is a 'proceed' link button. on clicking this button will go to the next page.on the next page there is a 'back' link button.I want a code such that when click on this back button then the values that have been entered in the previous page is preserved(i.e displayed on the controls in which have been filled).Can anyone help me 开发者_Python百科for solving this simple problem?


I know this is not a direct answer to your question, but it may be a simpler approach:

Just a suggestion, but long as you're using ASP.NET consider not using separate pages, but instead use the Wizard control.

It sounds like you're creating a wizard-style interface anyway, and the Wizard control solves a lot of these issues for you a lot more simply than other approaches. It "just works" and works beautifully.

This page has even more useful links: http://weblogs.asp.net/scottgu/archive/2006/02/21/438732.aspx


Typically I will accomplish this by having an id or ids in the query string that allow me to query the database to retrieve the information entered for the page.

So if you have your back button link to this url: http://www.mySite.com/PrevPage.aspx?id=1234

You would have the onload event for PrevPage.aspx do do this (psudo code):

//Query database for record with id 1234

//Foreach record populate the appropriate controls with the data returned from the DB.


Store the control values in the first page in Session. On click of the 'back' button in the second page get the values stored in Session and load in the first page controls.

Page1.aspx

 <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <br />
 <asp:Button ID="Button1" runat="server" Text="Next" onclick="Button1_Click" />

Page1.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["Name"] != null)
                txtName.Text = Session["Name"].ToString();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["Name"] = txtName.Text;
        Response.Redirect("Page2.aspx");
    }

Page2.aspx

<asp:Button ID="Button1" runat="server" Text="Back" onclick="Button1_Click" />

Page2.aspx.cs

 protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Page1.aspx");
    }
0

精彩评论

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

关注公众号