Hi.
I have four buttons for changing stylesheet with IDs BTN_RED, BTN_GREEN, BTN_BLUE, BTN_YELLOW.
When I click one of them, I want to post back to this page while theme is changed.
I want to change href attribute of stylesheet, to corresponding stylesheet.
Here's master page cs file: (LINK_StyleSheet is id of link tag in header)
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Theme"] == null)
LINK_StyleSheet.Href = "~/Styles/blue.css";
else
LINK_StyleSheet.Href = Session["Theme"].ToString();
}
protected void BTN_RED_Click(object sender, EventArgs e)
{
Session["Theme"] = "~/Styles/red.css";
}
and also for three other buttons.
But site theme will change when I click a single button two times.
First time I click a button, it does not change the theme. second time, I click that, it will change.
What's the problem.
Problem with asp button postback
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Suthish NairRank #92 · 22.8K reputationPosted Jun 26, 2011, 9:23 AM EDT
Majid KamaliRank #6,453 · 266 reputationPosted Jun 26, 2011, 9:36 AM EDT
with this ( if(!IsPostBack){}) ), it does not change theme at all because it does not run what is within if statement.