小弟使用作了一个更新个人信息的页面,成功后使用“ Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx';</script>");”session是一直保存着的,但是跳转到XXX.aspx页面却发现session没了,这是为什么请指教、并且请告之修改的方法谢谢。
调试欢乐多
Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx?id="+你要传的参数+"';</script>");”
上代码吧 !
web.config:
<system.web>
<sessionState timeout="30" mode="InProc">
</sessionState>
如果存在的话那证明你XXX.aspx页面有一些逻辑操作会导致Session过期,
比如说你修改了Config文件之类的。
{
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>");
}
}提交代码
应该在Response.Write("<script language='javascript'>alert('更新成功');window.location.href='XXX.aspx';</script>");
前session['卡号']=卡号
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>");
}
}
"<script>alert('更新成功');
window.location.href ='XXX.aspx';
</script>");
这样看
前台
<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都会没有了
这是什么原因?