小弟使用作了一个更新个人信息的页面,成功后使用“ Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx';</script>");”session是一直保存着的,但是跳转到XXX.aspx页面却发现session没了,这是为什么请指教、并且请告之修改的方法谢谢。

解决方案 »

  1.   

    你session里存的是什么啊 你也可以这样写的
    Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx?id="+你要传的参数+"';</script>");”
      

  2.   

    session存的是卡号,不详id是因为会被人看到。
      

  3.   

    session 取不到值吗?
    上代码吧 !
      

  4.   


    web.config:
    <system.web>
        <sessionState timeout="30" mode="InProc">
            </sessionState>
      

  5.   

    你可以新建一个空页面然后跳过去,检查Session是否存在。
    如果存在的话那证明你XXX.aspx页面有一些逻辑操作会导致Session过期,
    比如说你修改了Config文件之类的。
      

  6.   

    protected void sure_Click(object sender, EventArgs e)
        {
            string cardcode, name, idcard, birthday, phone, mail, postcode, address, sexvalue, provincevalue, regionvalue, idvalue;
            cardcode = this.cardtxt.Text.Trim().ToString();
            name = this.nametxt.Text.Trim().ToString();
            idcard = this.idcardtxt.Text.Trim().ToString();
            birthday = this.birthdaytxt.Text.Trim().ToString();
            phone = this.phonetxt.Text.Trim().ToString();
            mail = this.mailtxt.Text.Trim().ToString();
            postcode = this.postcardtxt.Text.Trim().ToString();
            address = this.addresstxt.Text.Trim().ToString();
            sexvalue = this.sex.SelectedValue;
            provincevalue = this.provincelist.SelectedValue;
            regionvalue = this.regionlist.SelectedValue;
            idvalue = this.idlist.SelectedValue;
             if ( cardcode == "")
             {
                 message.Visible = true;
                 this.message.Text = "卡号不能为空";
                 return;
             }
             else if (name == "")
             {
                 message.Visible = true;
                 this.message.Text = "姓名不能为空";
                 return;
             }
             else if (idcard == "")
             {
                 message.Visible = true;
                 this.message.Text = "证件号码不能为空";
                 return;
             }
             else if (Convert.ToInt32(this.idlist.SelectedValue) == 0001)
            {
                string zjcode = this.idcardtxt.Text.Trim();
                if (zjcode.Length != 15 && zjcode.Length != 18)
                {
                    message.Visible = true;
                    this.message.Text = "您输入的证件长度不正确!请重试!";
                    return;
                }
             }
             else if (birthday == "")
             {
                 message.Visible = true;
                 this.message.Text = "生日不能为空";
                 return;
             }
             else if (phone == "")
             {
                 message.Visible = true;
                 this.message.Text = "手机号不能空";
                 return;
             }
             else if (phone.Length < 11 || phone.Length > 11)
             {
                 message.Visible = true;
                 this.message.Text = "手机号长度需11位";
                 return;
             }
             else if (mail == "")
             {
                 message.Visible = true;
                 this.message.Text = "邮箱不能为空";
                 return;
             }
             else if (postcode == "")
             {
                 message.Visible = true;
                 this.message.Text = "邮编不能为空";
                 return;
             }
             else if (address == "")
             {
                 message.Visible = true;
                 this.message.Text = "家庭地址不能为空";
                 return;
             }
             try { Convert.ToDateTime(birthday); }
             catch
             {
                 message.Visible = true;
                 this.message.Text = "日期格式错误,请重新填写";
                 return;
             }             SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                 conn.Open();
                 string sqlstr = "update table27 set col26='"+name+"',col25='"+sexvalue+"',col21='"+provincevalue+"',col23='"+regionvalue+"',col9='"+address+"',col29='"+postcode+"',col4='"+birthday+"',";
                 sqlstr = sqlstr + "col18='" + phone + "',col15='" + idcard + "',col31='" + idvalue + "',col17='" + mail + "' where col16='"+cardcode+"'";
                 SqlCommand cmd = new SqlCommand(sqlstr, conn);
                 try { int res = cmd.ExecuteNonQuery(); }
                 catch (Exception ex) { Response.Write("<script language='javascript'>alert('更新失败');</script>"); conn.Close(); return; }
                 finally
                 {
                     conn.Close();
                    Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx';</script>");                 
                 }
             }提交代码
      

  7.   

    从头到尾没看到你在哪给SESSION赋值的???
    应该在Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx';</script>");   
    前session['卡号']=卡号
      

  8.   


    protected void sure_Click(object sender, EventArgs e)
      {
      string cardcode, name, idcard, birthday, phone, mail, postcode, address, sexvalue, provincevalue, regionvalue, idvalue;
      cardcode = this.cardtxt.Text.Trim().ToString();
      name = this.nametxt.Text.Trim().ToString();
      idcard = this.idcardtxt.Text.Trim().ToString();
      birthday = this.birthdaytxt.Text.Trim().ToString();
      phone = this.phonetxt.Text.Trim().ToString();
      mail = this.mailtxt.Text.Trim().ToString();
      postcode = this.postcardtxt.Text.Trim().ToString();
      address = this.addresstxt.Text.Trim().ToString();
      sexvalue = this.sex.SelectedValue;
      provincevalue = this.provincelist.SelectedValue;
      regionvalue = this.regionlist.SelectedValue;
      idvalue = this.idlist.SelectedValue;
      if ( cardcode == "")
      {
      message.Visible = true;
      this.message.Text = "卡号不能为空";
      return;
      }
      else if (name == "")
      {
      message.Visible = true;
      this.message.Text = "姓名不能为空";
      return;
      }
      else if (idcard == "")
      {
      message.Visible = true;
      this.message.Text = "证件号码不能为空";
      return;
      }
      else if (Convert.ToInt32(this.idlist.SelectedValue) == 0001)
      {
      string zjcode = this.idcardtxt.Text.Trim();
      if (zjcode.Length != 15 && zjcode.Length != 18)
      {
      message.Visible = true;
      this.message.Text = "您输入的证件长度不正确!请重试!";
      return;
      }
      }
      else if (birthday == "")
      {
      message.Visible = true;
      this.message.Text = "生日不能为空";
      return;
      }
      else if (phone == "")
      {
      message.Visible = true;
      this.message.Text = "手机号不能空";
      return;
      }
      else if (phone.Length < 11 || phone.Length > 11)
      {
      message.Visible = true;
      this.message.Text = "手机号长度需11位";
      return;
      }
      else if (mail == "")
      {
      message.Visible = true;
      this.message.Text = "邮箱不能为空";
      return;
      }
      else if (postcode == "")
      {
      message.Visible = true;
      this.message.Text = "邮编不能为空";
      return;
      }
      else if (address == "")
      {
      message.Visible = true;
      this.message.Text = "家庭地址不能为空";
      return;
      }
      try { Convert.ToDateTime(birthday); }
      catch
      {
      message.Visible = true;
      this.message.Text = "日期格式错误,请重新填写";
      return;
      }  SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
      conn.Open();
      string sqlstr = "update table27 set col26='"+name+"',col25='"+sexvalue+"',col21='"+provincevalue+"',col23='"+regionvalue+"',col9='"+address+"',col29='"+postcode+"',col4='"+birthday+"',";
      sqlstr = sqlstr + "col18='" + phone + "',col15='" + idcard + "',col31='" + idvalue + "',col17='" + mail + "' where col16='"+cardcode+"'";
      SqlCommand cmd = new SqlCommand(sqlstr, conn);
      try { int res = cmd.ExecuteNonQuery(); }
      catch (Exception ex) { Response.Write("<script language='javascript'>alert('更新失败');</script>"); conn.Close(); return; }
      finally
      {
      conn.Close();
      Session["Number"]=cardcode;
      Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx';</script>");   
      }
      }
      

  9.   

     Session["Number"]=cardcode;  没用?
      

  10.   

    ClientScript.RegisterStartupScript(Page.GetType(), "", 
    "<script>alert('更新成功');
    window.location.href ='XXX.aspx';
    </script>");
    这样看
      

  11.   

    用了大家的方法都不行除了在下面再次复制session外。但是其他的session还是会没,后来发现因为我做了一个身份证件的判断
    前台
     <td style="width: 95px; height: 24px;">
                        证件号码:</td>
                    <td style="width: 255px; height: 24px;">
                        <asp:TextBox ID="idcardtxt" runat="server" Enabled="False"  onblur="lostfocus()"></asp:TextBox>
                          <asp:label id="errorzj" Runat="server" ForeColor="Red" Font-Size="12px"></asp:label>
                <asp:Button ID="checkzj" runat="server" Text="查询证件"   Width="10px" CausesValidation="false" OnClick="checkzj_Click" style="visibility:hidden" /></td>
     <script  type="text/javascript">
    function lostfocus()
    {
        document.getElementById('checkzj').click();   
    }  
       </script>后台
    protected void checkzj_Click(object sender, EventArgs e)
        {
            errorzj.Text = "";
            string date = "";
            if (Convert.ToInt32(this.idlist.SelectedValue) == 0001)
            {
                string zjcode = this.idcardtxt.Text.Trim();
                if (zjcode.Length != 15 && zjcode.Length != 18)
                {
                    errorzj.Text = "证件长度不正确!";
                }
                else if (zjcode.Length == 15)
                {
                    date = 19 + zjcode.Substring(6, 2) + '-' + zjcode.Substring(10, 2) + '-' + zjcode.Substring(12, 2);
                    birthdaytxt.Text= date;            }
                else if (zjcode.Length == 18)
                {
                    date = zjcode.Substring(6, 4) + '-' + zjcode.Substring(10, 2) + '-' + zjcode.Substring(12, 2);
                    birthdaytxt.Text = date;
                }
            }
    只要出现提示errorzj错误,那么当修改好以后,提交跳转session都会没有了 
    这是什么原因?
      

  12.   

    建议不要使用Session,现在的服务器很容易丢失Session的。建议改用Cookie
      

  13.   

    确实,而且有时候丢失Session是程序压根没什么办法解决的。
      

  14.   

    恩 用cookie吧 用法和session类似