Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,

I want to maintain the value of the radio button which is on first page. If i navigate to second page and click back button to come on first page. The value of the radio button should be same as previously selected. So how to maintain this?

The first page (i.e.Homepage.aspx) has radio button Pick Up, PNR Number, Train Number, Home Delivery which is a 2 radio button list control. PNR Number and Train Number are in RadioBtnOrder and Home delivery and pick up are in list RadioBtnOrder1.The default is radio button PNR Number gets selected. If user selects radio button Pick Up or any other, and then if he go to second page (i.e. MenuDetail.aspx), I want to keep the previous selection when coming back to page one by clicking on browsers back button.

I have tried maintaining the session but i am not gettting that where i am going wrong.

My Code is :

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace JustFood
{
    public partial class Homepage : System.Web.UI.Page
    {

        JFAdminBL.Menu menu = new JFAdminBL.Menu();
        JFAdminBL.Outlet outlet = new JFAdminBL.Outlet();
        JFAdminBL.Vendor ven = new JFAdminBL.Vendor();

        string juerneydate = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
          if (!Page.IsPostBack)
          {

              try
              {
                    DataSet ds2 = outlet.CityData();

                    DDLCITY.DataTextField = ds2.Tables[0].Columns[0].ToString();

                    DDLCITY.DataSource = ds2;

                    DDLCITY.DataBind();

                    DataSet ds3 = outlet.CityData();

                    DDLCITYPICKUP.DataTextField = ds3.Tables[0].Columns[0].ToString();

                    DDLCITYPICKUP.DataSource = ds3;

                    DDLCITYPICKUP.DataBind();
                    DDLCITYPICKUP.Items.Insert(0, "Select City");

                    DataSet dsAllVendors = ven.wsGetAllVendors();

                    dsAllVendors.Tables[0].Columns["Name"].ColumnName = "Partners";

                    //gridAllVendors.DataSource = dsAllVendors;

                    //gridAllVendors.DataBind();
                }
                catch (Exception ex)
                {


                }
                pnrPanel.Visible = true;
            }
        }
protected void RadioBtnOrder_SelectedIndexChanged(object sender, EventArgs e)
       {

           //System.Threading.Thread.Sleep(500);
           string SelectedRadBtnVal = RadioBtnOrder.SelectedValue;
           //System.Windows.Forms.MessageBox.Show(SelectedRadBtnVal);
           RadioBtnOrder1.SelectedIndex = -1;

           txtpnrno.Visible = false;
           labPNRno.Visible = false;
           btnSubmitPNR.Visible = false;

           LabelTrainNoTrain.Visible = false;
           txttrainnotrain.Visible = false;
           LabelCoachNoTrain.Visible = false;
           txtcoachnotrain.Visible = false;
           LabelSeatNoTrain.Visible = false;
           txtseatnotrain.Visible = false;
           LabelSelectStationTrain.Visible = false;
           DDLStationNametrain.Visible = false;
           LabelDate.Visible = false;
           //Calendartrain.Visible = false;
           //  btnsubmmittrain.Visible = false;
           LabelStreet1.Visible = false;
           LabelStreet2.Visible = false;
           LabelLandMark.Visible = false;
           LabelPinCode.Visible = false;
           txtStreet1.Visible = false;
           txtStreet2.Visible = false;
           txtLandmark.Visible = false;
           txtPinCode.Visible = false;
           btnHomeDel.Visible = false;
           LabelCityHomeDelivery.Visible = false;
           DDLCITY.Visible = false;

           LabelCityPickUp.Visible = false;
           DDLCITYPICKUP.Visible = false;

           if (SelectedRadBtnVal.Equals("PNR Number"))
           {

               Session["PNR Number"] = RadioBtnOrder.SelectedValue;

               trainPanel.Visible = false;
               homePanel.Visible = false;
               pickPanel.Visible = false;


               labPNRno.Visible = true;
               txtpnrno.Visible = true;
               btnSubmitPNR.Visible = true;
               pnrPanel.Visible = true;
           }
           else if (SelectedRadBtnVal.Equals("Train Number"))
           {
               Session["Train Number"] = RadioBtnOrder.SelectedValue;

               pnrPanel.Visible = false;
               homePanel.Visible = false;
               pickPanel.Visible = false;
               LabelTrainNoTrain.Visible = true;
               txttrainnotrain.Visible = true;
               //LabelCoachNoTrain.Visible = true;
               //txtcoachnotrain.Visible = true;
               //LabelSeatNoTrain.Visible = true;
               //txtseatnotrain.Visible = true;
               //LabelSelectStationTrain.Visible = true;
               //DDLStationNametrain.Visible = true;
               LabelDate.Visible = true;
               // Calendartrain.Visible = true;
               //btnsubmmittrain.Visible = true;
               trainPanel.Visible = true;
           }
           else if (SelectedRadBtnVal.Equals("Home Delivery"))
           {
               Session["Home Delivery"] = RadioBtnOrder.SelectedValue;

               trainPanel.Visible = false;
               pnrPanel.Visible = false;
               pickPanel.Visible = false;
               LabelStreet1.Visible = true;
               LabelStreet2.Visible = true;
               LabelLandMark.Visible = true;
               LabelPinCode.Visible = true;
               txtStreet1.Visible = true;
               txtStreet2.Visible = true;
               txtLandmark.Visible = true;
               txtPinCode.Visible = true;
               btnHomeDel.Visible = true;
               LabelCityHomeDelivery.Visible = true;
               DDLCITY.Visible = true;
               homePanel.Visible = true;
           }
           else if (SelectedRadBtnVal.Equals("Pick Up"))
           {
               Session["Pick Up"] = RadioBtnOrder.SelectedValue;

               trainPanel.Visible = false;
               homePanel.Visible = false;
               pnrPanel.Visible = false;
               LabelCityPickUp.Visible = true;
               DDLCITYPICKUP.Visible = true;
               pickPanel.Visible = true;
           }

       }

       protected void RadioBtnOrder1_SelectedIndexChanged(object sender, EventArgs e)
       {
           System.Threading.Thread.Sleep(3000);
           string SelectedRadBtnVal = RadioBtnOrder1.SelectedValue;
           //System.Windows.Forms.MessageBox.Show(SelectedRadBtnVal);
           RadioBtnOrder.SelectedIndex = -1;

           txtpnrno.Visible = false;
           labPNRno.Visible = false;
           btnSubmitPNR.Visible = false;

           LabelTrainNoTrain.Visible = false;
           txttrainnotrain.Visible = false;
           LabelCoachNoTrain.Visible = false;
           txtcoachnotrain.Visible = false;
           LabelSeatNoTrain.Visible = false;
           txtseatnotrain.Visible = false;
           LabelSelectStationTrain.Visible = false;
           DDLStationNametrain.Visible = false;
           LabelDate.Visible = false;
           //Calendartrain.Visible = false;
           //  btnsubmmittrain.Visible = false;
           LabelStreet1.Visible = false;
           LabelStreet2.Visible = false;
           LabelLandMark.Visible = false;
           LabelPinCode.Visible = false;
           txtStreet1.Visible = false;
           txtStreet2.Visible = false;
           txtLandmark.Visible = false;
           txtPinCode.Visible = false;
           btnHomeDel.Visible = false;
           LabelCityHomeDelivery.Visible = false;
           DDLCITY.Visible = false;

           LabelCityPickUp.Visible = false;
           DDLCITYPICKUP.Visible = false;

           if (SelectedRadBtnVal.Equals("PNR Number"))
           {
               Session["PNR Number"] = RadioBtnOrder1.SelectedValue;

               trainPanel.Visible = false;
               homePanel.Visible = false;
               pickPanel.Visible = false;


               labPNRno.Visible = true;
               txtpnrno.Visible = true;
               btnSubmitPNR.Visible = true;
               pnrPanel.Visible = true;
           }
           else if (SelectedRadBtnVal.Equals("Train Number"))
           {
               Session["Train Number"] = RadioBtnOrder1.SelectedValue;

               pnrPanel.Visible = false;
               homePanel.Visible = false;
               pickPanel.Visible = false;
               LabelTrainNoTrain.Visible = true;
               txttrainnotrain.Visible = true;
               //LabelCoachNoTrain.Visible = true;
               //txtcoachnotrain.Visible = true;
               //LabelSeatNoTrain.Visible = true;
               //txtseatnotrain.Visible = true;
               //LabelSelectStationTrain.Visible = true;
               //DDLStationNametrain.Visible = true;
               LabelDate.Visible = true;
               // Calendartrain.Visible = true;
               // btnsubmmittrain.Visible = true;
               trainPanel.Visible = true;
           }
           else if (SelectedRadBtnVal.Equals("Home Delivery"))
           {
               Session["Home Delivery"] = RadioBtnOrder1.SelectedValue;

               trainPanel.Visible = false;
               pnrPanel.Visible = false;
               pickPanel.Visible = false;
               LabelStreet1.Visible = true;
               LabelStreet2.Visible = true;
               LabelLandMark.Visible = true;
               LabelPinCode.Visible = true;
               txtStreet1.Visible = true;
               txtStreet2.Visible = true;
               txtLandmark.Visible = true;
               txtPinCode.Visible = true;
               btnHomeDel.Visible = true;
               LabelCityHomeDelivery.Visible = true;
               DDLCITY.Visible = true;
               homePanel.Visible = true;
           }
           else if (SelectedRadBtnVal.Equals("Pick Up"))
           {
               Session["Pick Up"] = RadioBtnOrder1.SelectedValue;

               trainPanel.Visible = false;
               homePanel.Visible = false;
               pnrPanel.Visible = false;
               LabelCityPickUp.Visible = true;
               DDLCITYPICKUP.Visible = true;
               pickPanel.Visible = true;
           }
       }
       
   }
}


Please help me.

Thanks in advance....
Posted
Updated 18-Sep-12 3:04am
v5
Comments
[no name] 18-Sep-12 9:06am    
My vote of 4:
Please avoid writing the whole code in the question.
rp786 18-Sep-12 12:47pm    
Ok. I wrote it just as i was not getting how to solve it.

While moving to the second page you'll have to store the value of RadioButton in Session/cache/cookies etc. And in page load of the first page check for that. Like:
In page load event of 1st page:
C#
//Check for the session
if(Session["Test"] != null)
{
    //If exists then set the value
    radioButton1.Checked = Convert.ToBoolean(Session["Test"]);
}

While redirecting the page:
C#
//set the session value to maintain the radioButton
Session["Test"] = radioButton1.Checked;
//Redirect to another page
Response.Redirect("Test.aspx");



--Amit
 
Share this answer
 
Comments
Andrei Straut 18-Sep-12 3:52am    
Pretty. Upvoted solution
_Amy 18-Sep-12 4:39am    
Thank you Straut. :)
just try enable viewstate property and check behavior in these two approaches:
response.redirect(uri)
server.transfer(uri)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900