protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if ()
        {   // 操作类型:添加
            // 添加随访记录
            string strcontant = this.txtcontant.Text;
            string strresults = this.txtresults.Text;
            int upuserid = Utils.GetQueryInt("userid");
            Addfollowup(strcontant, strresults, upuserid);            int mi = (int)Enums.MenuType.随访信息;
            int ui = Utils.GetQueryInt("userId");
            Response.Write("<script>alert('添加成功');window.location.href='followupvisit.aspx?mid=" + mi + "&userid=" + ui + "';</script>"); 
        }
        else
        {   
            // 操作类型:编辑
            // 编辑随访记录
            int conid = Utils.GetQueryInt("contentid");
            string follcon = this.txtcontant.Text.Trim();
            string follres = this.txtresults.Text.Trim();
            Updfollowup(conid,follcon,follres);            int mi = (int)Enums.MenuType.随访信息;
            int ui = Utils.GetQueryInt("userId");
            Response.Write("<script>alert('修改成功');window.location.href='followupvisit.aspx?mid=" + mi + "&userid=" + ui + "';</script>"); 
        }
    }我应该如何判断这两个方法,能不能通过前面点击按钮来判断,比如:点击添加,判断是添加方法,点击修改判断是修改方法呢?

解决方案 »

  1.   

    是编辑的话,model肯定不等于空,判断一下model,空是添加,否则更新
      

  2.   


    我查了一下,说在按钮连接的时候传过来一个参数判断这个参数就成了如:在页面地址上使用问号传参。 
    比如 
    modify.aspx?action=add       添加 
    modify.aspx?action=modify     修改 通过Request取值就可以了到if判断时候怎么写?大家看看可以吗?
      

  3.   

    string aa=Request.QueryString["add"];
    if(aa=="add")
    {
    //添加
    }else{
    //修改
    }
      

  4.   

    太意了,是这样的string aa=Request.QueryString["action"];
    if(aa=="add")
    {
    //添加
    }else{
    //修改
    }
      

  5.   

    modify.aspx?action=add 添加 
    modify.aspx?action=modify 修改 太意了,是这样的string aa=Request.QueryString["action"];
    if(aa=="add")
    {
     btAdd.Visible = true;添加按钮
     btUpdate.Visible = false;修改按钮
    }else{
     btAdd.Visible = false;添加按钮
     btUpdate.Visible = true;修改按钮
    } 代码差不多就这样
      

  6.   

    新增跟编辑,可以共用一个页面
    你的那个记录,有没有一个主键,编辑的时候将这个主键传进来
    然后在这个页面,Request.QueryString获取主键,如果为空,则为添加,如果不为空,则为编辑确定按钮的方法这样:
     if(!string.isNullOrEmpty(Request.QueryString["id"]))
    {
     Update()//更新方法
    }
    else
    {
    Add(); //添加方法
    }
      

  7.   

    我是在一个页面用asp:input做的添加按钮,在repeater中用的label加上<a>