我在学习用asp.net时遇到一个问题代码如下:
ST_CourseBiz.ST_Dept st_dept=new ST_CourseBiz.ST_Dept();
if(Request["Action"]=="add")
{
st_dept.ST_InsertDeptInfo(txtName.Text.Trim(),int.Parse(txtNumber.Text));
}
else
{
st_dept.ST_UpdateDeptInfo(txtName.Text.Trim(),int.Parse(txtNumber.Text));
string str="<script language=javascript>window.dialogArguments.document.location.href='ST_Dept.aspx';window.close();</script>";
Response.Write(str);
}
其中Request["Action"]里的Action是怎样赋值的?

解决方案 »

  1.   

    A页面:  a.aspx; B页面:  b.aspx;
    如从A页面转到B页面: 则可在A页面的后台代码里写 Respose.Redirect("b.aspx?Action=add");
    同样B页面的后台代码里则可以写 if(Request["Action"]=="add") 
    这种在URL后面用?传递参数的方法为GET方法,还有POST,这两种是最常用的
      

  2.   

    Respose.Redirect("x.aspx?Action="+传值)
    取时用Request.QueryString["Action"]
    还可以用cookie session  application 和静态变量传值
      

  3.   

    谢谢!我遇到的问题是这样的:根据action的不同edit修改 add则添加,无论修改还是添加都是一个页面,这个页面用下面的代码生成:
    public void dgItem(object sender,DataGridCommandEventArgs e)
    {
    ST_CourseBiz.ST_Dept st_dept=new ST_CourseBiz.ST_Dept();
    int st_deptID=int.Parse(e.Item.Cells[0].Text);
    if(e.CommandName=="edit")
    {
    string str="<script language='javascript' defer>ret=window.showModalDialog('ST_DeptAdd.aspx',' Action=edit&id="+st_deptID+"','dialogHeight;250px;dialogWidth:600px;center:Yes;Help:No;Resizable:No;Scroll;auto;Status:no;');</script>";
    Response.Write(str);
    if(e.CommandName=="delete")
    {
    st_dept.ST_DeleteDeptInfo(st_deptID);
    }
    ST_DgBind();
    }
    }
    但是在用到
    if(Request["Action"]=="add")
    {
    st_dept.ST_InsertDeptInfo(txtName.Text.Trim(),int.Parse(txtNumber.Text));
    }
    else
    {
    st_dept.ST_UpdateDeptInfo(txtName.Text.Trim(),int.Parse(txtNumber.Text));
    string str="<script language=javascript>window.dialogArguments.document.location.href='ST_Dept.aspx';window.close();</script>";
    Response.Write(str);
    }
    时不对,ST_UpdateDeptInfo绑定不了,但是去掉if(Request["Action"]=="add")就可以,不知道哪里出的问题?
      

  4.   

    取时用Request.QueryString["Action"] 
    比如先定义一个string a ="111";
    然后取值a = Convert.ToString(Request.QueryString["Action"]);
    你先 Response.Wirte(a);把你取的值输出 看看得到的是什么
    如果是111 则没取到 你测试下
      

  5.   

    谢谢!那我想问下QueryString的作用是什么?