检索选中的复选框值从previous页 [英] Retrieve Selected Checkbox Value From Previous Page

查看:132
本文介绍了检索选中的复选框值从previous页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 asp.net网络表单网​​站,在会话和第3页上存储数据显示的条目上的PG1和放大器输入; PG2。

在第一页的第一个复选框是$ P $默认情况下,对选择,但如果用户选择/取消选择复选框,当用户在第二页上,有一个后退按钮,但它的点击,当我穿上'知道如何重新显示选定/未选定为唯一一个被选中默认的复选框。

我是新来使用 ASP 和会话存储,所以我可能会做一些完全错了,所以请告知我,如果我还帮我解决我的情况,而不仅仅是否决没有解释后。

反正我的code是:

HTML

 < D​​IV CLASS =表单组>
     < D​​IV CLASS =COL-XS-偏移0 COL-SM-偏移4 COL-SM-3>所有服务和LT; / DIV>
     < D​​IV CLASS =COL-SM-1>
          < ASP:复选框ID =Step02AllServices=服务器选中=真/>
     < / DIV>
< / DIV>
< D​​IV CLASS =表单组>
     < D​​IV CLASS =COL-XS-偏移0 COL-SM-偏移4 COL-SM-3>网站内容上传只< / DIV>
     < D​​IV CLASS =COL-SM-1>
          < ASP:复选框ID =Step02ContentUploading=服务器/>
     < / DIV>
< / DIV>
< D​​IV CLASS =表单组>
     < D​​IV CLASS =COL-XS-偏移0 COL-SM-偏移4 COL-SM-3>网站内容和放大器;放大器;布局检查< / DIV>
     < D​​IV CLASS =COL-SM-1>
          < ASP:复选框ID =Step02ContentLayoutChecking=服务器启用=FALSE/>
     < / DIV>
< / DIV>

code背后

 保护无效Step02SubmitButton_Click(对象发件人,EventArgs的发送)
{
     会话[Step02AllServices] = Step02AllServices.Checked;
     会话[Step02ContentUploading] = Step02ContentUploading.Checked;
     会话[Step02ContentLayoutChecking] = Step02ContentLayoutChecking.Checked;
     的Response.Redirect(/报价/ pg3.aspx);
}

我知道这是需要在我的的Page_Load 只是不知道如何做到这一点。

下面是我对另一个页面

在单选按钮和测试领域

 如果(txtData2.Text ==&的String.Empty功放;&安培;会议[PG2]!= NULL)
{
     。txtData2.Text =会话[PG2]的ToString();     如果(会话[pg2Yes]。的ToString()==是)
     {
          。pg2Yes.Checked =会话[pg2Yes]等于(是);
     }     如果(会话[pg2No]。的ToString()==否)
     {
          pg2No.Checked =会话[pg2No]等于(否)。
     }
}


解决方案

让我们假设你是第3页,并且单击后退按钮您重定向到第2页。

在第2页的负荷,你需要检查它是否是一个新的负载(不回发),如果包含在会话中的值。如果两个都是真的,你需要从会议的价值,使该复选框选中。

所以,写Page2Load以下code

  //如果要加载新页面
如果(!Page.IsPostBack)
{
    如果(会话[Step02AllServices]!= NULL)
    {
        Step02AllServices.Checked =(布尔)会议[Step02AllServices];
        //同样指定其他复选框的值,因为他们在会议上已经
    }
    其他
    {
        //做正常作业
    }
}

I have an asp.net webform website which stores data in a session and on the 3rd page displays the entries entered on pg1 & pg2.

On the first page the first checkboxes is pre-selected by default but if the user selects/unselects a checkbox, when the user is on the second page, there is a back button but when it's clicked I don't know how to re-show the checkboxes selected/unselected as only the default one is checked.

I'm new to using asp and session storing so I may be doing something completely wrong so please advise me if I am and also help me to resolve my situation rather than just voting down the post with no explanation.

Anyway my code is:

HTML

<div class="form-group">
     <div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">All services</div>
     <div class="col-sm-1">
          <asp:CheckBox ID="Step02AllServices" runat="server" Checked="True" />
     </div>
</div>
<div class="form-group">
     <div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Site content uploading only</div>
     <div class="col-sm-1">
          <asp:CheckBox ID="Step02ContentUploading" runat="server" />
     </div>
</div>
<div class="form-group">
     <div class="col-xs-offset-0 col-sm-offset-4 col-sm-3">Site content &amp; layout checking</div>
     <div class="col-sm-1">
          <asp:CheckBox ID="Step02ContentLayoutChecking" runat="server" Enabled="False" />
     </div>
</div>

Code Behind

protected void Step02SubmitButton_Click(object sender, EventArgs e)
{
     Session["Step02AllServices"] = Step02AllServices.Checked;
     Session["Step02ContentUploading"] = Step02ContentUploading.Checked;
     Session["Step02ContentLayoutChecking"] = Step02ContentLayoutChecking.Checked;
     Response.Redirect("/Quotation/pg3.aspx");
}

I know that is needs to be in my Page_Load just not sure how to do it.

The below is what I have for radio buttons and test fields on another page

if (txtData2.Text == string.Empty && Session["pg2"] != null)
{
     txtData2.Text = Session["pg2"].ToString();

     if (Session["pg2Yes"].ToString() == "Yes")
     {
          pg2Yes.Checked = Session["pg2Yes"].Equals("Yes");
     }

     if (Session["pg2No"].ToString() == "No")
     {
          pg2No.Checked = Session["pg2No"].Equals("No");
     }
}

解决方案

Let's assume that you are on page 3 and you clicked the back button which redirects you to page 2.

On load of page 2, you need to check whether it's a new load (not postback) and if it contains the values on session. If both are true, you need to get the value from session and make the checkbox selected.

So, write the following code in Page2Load

//if you are loading the new page
if (!Page.IsPostBack)
{
    if(Session["Step02AllServices"] != null)
    {
        Step02AllServices.Checked = (bool) Session["Step02AllServices"];
        //similarly assign other checkbox values as they are in session already
    }
    else
    {
        //do normal assignment
    }
}

这篇关于检索选中的复选框值从previous页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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