如果从第二页导航回去,如何保持第一页单选按钮的选择? [英] How to maintain the selection of radio button of first page if navigated back from the second page?

查看:96
本文介绍了如果从第二页导航回去,如何保持第一页单选按钮的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我要保留第一页上的单选按钮的值.如果我导航到第二页,然后单击后退"按钮进入第一页.单选按钮的值应与先前选择的值相同.那么如何维护呢?

第一页(即Homepage.aspx)具有单选按钮Pick Up,PNR编号,火车编号,送货到家,这是一个2单选按钮列表控件. PNR号和火车号在RadioBtnOrder中,送货到家和领取在RadioBtnOrder1列表中.默认情况下,已选中单选按钮PNR号.如果用户选择单选按钮Pick Up或其他任何按钮,然后转到第二页(即MenuDetail.aspx),则我想通过单击浏览器的后退按钮返回到第一页时保留先前的选择.

我曾尝试维护会议,但我不明白我要去哪里错了.

我的代码是:

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 :

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....

推荐答案

在移至第二页时,您必须将RadioButton的值存储在Session/cache/cookies等中.第一页的负载检查.喜欢:
第一页的页面加载事件:
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:
//Check for the session
if(Session["Test"] != null)
{
    //If exists then set the value
    radioButton1.Checked = Convert.ToBoolean(Session["Test"]);
}


重定向页面时:


While redirecting the page:

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




--mit




--Amit


只需尝试启用viewstate属性并检查以下两种方法的行为:
response.redirect(uri)
server.transfer(uri)
just try enable viewstate property and check behavior in these two approaches:
response.redirect(uri)
server.transfer(uri)


这篇关于如果从第二页导航回去,如何保持第一页单选按钮的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆