第二个母版页报这个,未将对象引用设置到对象的实例
弹出登录成功后,报的错。
登录正常页面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Entity;
using System.Data;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] == null)
{
Response.Write("<script>alert('对不起,请登录!'),location.href='UserLogin.aspx'</script>");
}
else
{
Bind();
}
}
public void Bind()
{
UserBusiness user = new UserBusiness();
UserEntity ue = new UserEntity();
ue.Uid = Session["uid"].ToString();
DataTable dt = new DataTable();
dt = user.FindUserInfo(ue);
DataList1.DataSource = dt;
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "more")
{
DataList1.SelectedIndex = e.Item.ItemIndex;
Bind();
}
if (e.CommandName == "back")
{
DataList1.SelectedIndex = -1;
Bind();
}
if (e.CommandName == "go")
{
Response.Redirect("UserBuy.aspx?pid=" + e.CommandArgument.ToString());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Business;
using Entity;
public partial class HomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
if (tbx_name.Text != "" && tbx_password.Text != "" && tbx_RandNum.Text != "")
{
UserEntity ue = new UserEntity();
ue.Uid= tbx_name.Text;
ue.Upw = tbx_password.Text;
UserBusiness ub = new UserBusiness();
int result = ub.ValidateUnameAndPS(ue);
if (result > 0)
{
Response.Write("<script>alert('登陆成功'),location.href='HomePage.aspx'</script>");
Session["uid"] = tbx_name.Text.Trim();
}
else
{
Response.Write("<script>alert('用户名和密码不匹配')</script>");
}
if (tbx_RandNum.Text == Session["RandNum"].ToString())
{
}
else
{
Response.Write("<script>alert('验证码输入错误')</script>");
}
}
else
{
Response.Write("<script>alert('所有项必须写')</script>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("UserRegiste.aspx");
}
}
登录错误页面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Entity;
using System.Data;
public partial class MasterPage2 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["aid"] == null)
{
Response.Write("<script>alert('对不起,请登录!'),location.href='AdministerLogin.aspx'</script>");
}
else
{
Bind();
}
}
public void Bind()
{
AdministerInfoBusiness a2 = new AdministerInfoBusiness();
AdministerInfoEntity a = new AdministerInfoEntity();
a.Aid = Session["aid"].ToString();
DataTable dt = new DataTable();
dt = a2.FindInfo(a);
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Entity;
using Business;
public partial class AdministerLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "" && TextBox2.Text != "")
{
AdministerInfoEntity ad = new AdministerInfoEntity();
ad.Aid = TextBox1.Text;
ad.Apw = TextBox2.Text;
AdministerInfoBusiness a = new AdministerInfoBusiness();
int res = 0;
res = a.ValidateAidAndPS(ad);
if (res > 0)
{
Response.Write("<script>alert('登陆成功'),location.href='AdministerMain.aspx'</script>");
Session["aid"] = TextBox1.Text.Trim();
}
else
{
Response.Write("<script>alert('用户名和密码不匹配')</script>");
}
if (TextBox3.Text == Session["RandNum"].ToString())
{
}
else
{
Response.Write("<script>alert('验证码输入错误')</script>");
}
}
else
{
Response.Write("<script>alert('所有项必须写')</script>");
}
}
}
应该是session的问题 但是第一个登录是正常显示的,在网上看到的方法,定位到session为空,断点调了下发现 控件的值为空。
看大佬们的解决办法 最开始是怀疑 代码顺序问题 先跳转了session未传出去,但是正常登录的那个是可以的啊。后来看的一些解决办法也有一些,但还是找不到根上。考虑用cookie了重新弄了,但是这个问题是什么啊,强迫症啊,想解决。难受。
标签:
相关文章
- 敏捷开发在互联网时代里的价值
- PL2586|替代FE1.1S|替代MA8601|USB2.0HUB集线器芯片|旺玖
- 力软快速开发平台,帮助中小企业躲过数字化“踏浪出海”的“暗礁”
- 软件开发:站在风口上的低代码
- TYPEC转HDMI方案|TYPEC扩展坞方案|CS5265设计4K60HZ TYPEC转HDMI方
- DP转HDMI2.0|DP转HDMI和VGA输出|CS5262AN方案应用|瑞奇达CS5262设计电
- Capstone瑞奇达|台湾瑞奇达|一级代理商|台湾瑞奇达科技有限公司
- CH7511B替代方案|CS5211设计方案|CS5211替代CH7511B|eDP转LVDS转接板
session值已经传出去了,但是接收值的控件有问题。我把那个控件删除,后正常了。
毫不客气的说 。这种代码 在外面企业开发 90%看不到