检查LoadViewState中是否单击了按钮
我收到了这个错误
Object reference null
在下面的代码中,如果我点击添加体验按钮时
eTarget = Request.Params["btnAddVisa"].ToString();
获取空错误
代码:
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if(IsPostBack)
{
eTarget = Request.Params["btnAddVisa"].ToString();
eTarget = Request.Params["btnAddExperience"].ToString();
}
if(eTarget == "Add Visa")
{
//
}
if(eTarget == "Add Experience")
{
//
}
}
protected void btnAddVisa_Click(sender,e)
{
//
}
protected void btnAddExperience_Click(sender,e)
{
//
}
有什么想法吗?提前致谢
答案 0 :(得分:0)
Request.Params["btnAddVisa"] may not have any object or value.
答案 1 :(得分:0)
您需要检查空值
if(Request.Params["btnAddVisa"]!=null)
eTarget = Request.Params["btnAddVisa"].ToString();
if(Request.Params["btnAddExperience"]!=null)
eTarget = Request.Params["btnAddExperience"].ToString();