0

当我在 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)
{
  //
}

有任何想法吗?提前致谢

4

2 回答 2

0
Request.Params["btnAddVisa"] may not have any object or value.
于 2013-10-03T07:03:38.393 回答
0

您需要检查空值

if(Request.Params["btnAddVisa"]!=null)
    eTarget = Request.Params["btnAddVisa"].ToString();
if(Request.Params["btnAddExperience"]!=null)
    eTarget = Request.Params["btnAddExperience"].ToString();
于 2013-10-03T07:04:12.427 回答