BlahWoo
BlahWoo

Reputation: 365

Saving radiobutton selection

I have radio buttons which I need to keep selected between pages. I have looked up all solutions but I am still confused on what I should do. I will supply the code which shows you the functions of the radio buttons

.aspx page

<p>What Is Your Budget?
<asp:RadioButton ID="High_B" GroupName="Budget" runat="server" Text="High" 
        oncheckedchanged="High_B_CheckedChanged" ViewStateMode="Enabled" 
        AutoPostBack="True">
    </asp:RadioButton>
     <asp:RadioButton ID="Low_B" GroupName="Budget" runat="server" Text="Low" 
        oncheckedchanged="Low_B_CheckedChanged" AutoPostBack="True" 
        ViewStateMode="Enabled"> 
    </asp:RadioButton>
 </p>
    <p>What is the level of excitement around FWC 2014?
     <asp:RadioButton ID="High_E" GroupName="Radio" runat="server" Text="High" 
        oncheckedchanged="High__E_CheckedChanged" ViewStateMode="Enabled" 
            AutoPostBack="True">
    </asp:RadioButton>
     <asp:RadioButton ID="Low_E" GroupName="Radio" runat="server" Text="Low" 
        oncheckedchanged="Low_E_CheckedChanged" AutoPostBack="True" 
            ViewStateMode="Enabled"> 
    </asp:RadioButton></p>

.aspx.cs page

public void Chart()
    {
        if (High_E.Checked && High_B.Checked)
        {

            DataSet dSet = new DataSet();
            dSet.ReadXml(Server.MapPath("~/ChartData/HighBud_Ex.xml"));
            Chart1.DataSource = dSet.Tables[0];
            Chart1.DataBind();
            Session["name"] = "High";
            setName();
        }

        if (High_E.Checked && Low_B.Checked)
        {
            DataSet dSet = new DataSet();
            dSet.ReadXml(Server.MapPath("~/ChartData/LowBud_HighEx.xml"));
            Chart1.DataSource = dSet.Tables[0];
            Chart1.DataBind();
            Session["name"] = "LowHigh";
            setName();
        }

        if (Low_E.Checked && High_B.Checked)
        {
            DataSet dSet = new DataSet();
            dSet.ReadXml(Server.MapPath("~/ChartData/HighBud_LowEx.xml"));
            Chart1.DataSource = dSet.Tables[0];
            Chart1.DataBind();
            Session["name"] = "HighLow";
            setName();
        }

        if (Low_E.Checked && Low_B.Checked)
        {
            DataSet dSet = new DataSet();
            dSet.ReadXml(Server.MapPath("~/ChartData/LowBud_Ex.xml"));
            Chart1.DataSource = dSet.Tables[0];
            Chart1.DataBind();
            Session["name"] = "Low";
            setName();

        }

Upvotes: 0

Views: 1857

Answers (2)

ashish agrawal
ashish agrawal

Reputation: 38

i too had this problem,i used session variable to store the state of radio buttons,what i did is at postback.I stored the state of radio buttons in a string seprated by comma and then when i needed to restore the state .i used the string split function to take the values in array n dependind on the string i restored the state of the controls

Upvotes: 0

ibrahimBadredine
ibrahimBadredine

Reputation: 66

You should preserve the state of your radioButtons between postbacks. That is, in oncheckedchanged event, save the state of your radiobutton in a Session for example, and after postback, set back those states.

Upvotes: 2

Related Questions