rohan panchal
rohan panchal

Reputation: 881

Back Button Code not working

I am using the following code for a "Back" Button:

<INPUT type="button" value="Button" onclick="window.history.back(); return true;"> 

But, on the Previous page I have two div elements. When the page loads it will show div1. The next time, when the button of div1 is clicked, div2 will show. On div2 I have a "Next" button. which redirects to the other page. I want code for a "Back" button, which will show div2 when Back is clicked. Also, If I use history.back() it will show div1.

HTML code

List all your liabilities as calculated on the day  the debt was forgiven to the debt was forgiven prior

NEXT
<div id="d2">
    <table cellspacing="3">
        <tr>
            <td colspan="2" class="styleh">
                <p>
                    <b>Part II. List the fair market value (FMV) of all your assets, calculated as of the
                        day prior to the debt being forgiven - this would be the "sell today, cash value."</b></p>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <button id="btncalc" onclick="return btncalc_onclick()">
                    Calculate</button>
                <button id="Button2" runat="server">
                    BACK</button>
            </td>
        </tr>
    </table>
</div>

Thank you in advance

Upvotes: 0

Views: 446

Answers (4)

Destrictor
Destrictor

Reputation: 752

If you want to remember what state the previous page was in, you'll have to use some sort of storage.

The methods I'm most familiar with is the session variable, but using it will require you to do the coding in the codebehind of the aspx page.

protected void url_onClick (object sender, EventArgs e) {
    Session["state"] = "div2";
    Response.Redirect("url_of_new_page");
}

Of course you'll have to create your page based on the state during Page_Load.

If you want do to it purely in javascript, you'll have to use cookies, which I can't explain unfortunately, but here's a link to w3schools.

Upvotes: 0

user1711092
user1711092

Reputation:

Try it :

<INPUT type="button" value="Button" onClick="history.go(-1);return true;"> 

OR

You can also try Asp.net Wizard Control for your scenerio.You can handle NextButtonClick
PreviousButtonClick events through this control.

Upvotes: 2

Amol Kolekar
Amol Kolekar

Reputation: 2325

I think you will have to maintain some state to accomplish this functionality...I would suggets you to use cookie for this..set cookie when you click second div and go to the next page (you would find lot of ways of setting cookie through javascript, Here is example) and when you go back to first page check this cookie and explicitly show the second div and immedietly clear that cookie so that it won't persist...this is the one way which came instantly in my mind...

Upvotes: 0

xfx
xfx

Reputation: 1948

change return true; to return false;

Upvotes: 1

Related Questions