1

I have a script that changes certain classes on buttons when the button is clicked. When you click the type-button it selects it then when you click the assigned-button it refreshes the page to load the form for the combination you selected.

$(document).ready(function () {
    $(".type-button").click(function () {
        $(this).toggleClass("btn-thinkware btn-success");
        $(".type-button").not(this)
           .removeClass("btn-success")
           .addClass("btn-thinkware");
    });
    $(".assigned-button").click(function () {
        $(this).toggleClass("btn-thinkware btn-success");
        $(".assigned-button").not(this)
           .removeClass("btn-success")
           .addClass("btn-thinkware");
    });
});

is it possible to hold the selected buttons on refresh? It only has to hold it on refresh, doesn't have to persist indefinitely, like if they leave the page and come back.

So when the new form loads based on the combination, can I hold the selected buttons new classes after the page reloads?

Is there a better way to do this? or am I on the right track?

1
  • refreshing the page loses all current page state. You should try ajax Commented Jul 13, 2015 at 13:22

2 Answers 2

1

since HTTP is stateless, you will need to persist your state somewhere. you could use AJAX to POST to a controller that stores the button state in Session, you could set a cookie value, or even set a querystring value.

A better solution may be to just refresh the part of the page that needs to be refreshed and leave your buttons.

Sign up to request clarification or add additional context in comments.

Comments

0

It seems like you are trying to implement a radio button here using two different buttons and changing their classes depending on which one the user clicks. If that is really the case, I would go ahead and use an asp:RadioButton, which is stateful and will persist across page refreshes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.