如何通过引用或URL获得previous页值 [英] how to get the value from previous page through reference or url

查看:237
本文介绍了如何通过引用或URL获得previous页值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code的页面,通过它我要传递的值

 保护无效UpdateDriver(对象发件人,EventArgs的发送)
        {
            按钮BTN =(按钮)发送;
            GridViewRow GVR =(GridViewRow)btn.NamingContainer;
            HiddenField隐藏=(HiddenField)gvr.Cells [0] .FindControl(hdnID);
            INT用户ID = Convert.ToInt32(hid.Value);
            字符串URL =UpdateDriver.aspx? +用户名=+用户名;
            的Response.Redirect(URL);
           // BalUsers.UpdateDriver();
         // HiddenField隐藏=(HiddenField)gridview1.Cells [0] .FindControl(hdnID);
          // BalUsers
        }

因此​​,在更新驱动程序页面我想要得到的用户名,并将其传递给我的CommandText

 保护无效的button1_Click(对象发件人,EventArgs的发送)
        {
            myconnection.Open();            cmd.CommandText =。UPDATE [Ovms_New] [DBO] [tbl_driver] SET [lisenceNO]​​ =('@lisenceNO'),[liscenceType] =('@liscenceType'),其中(用户ID ='@UserID');
            cmd.ExecuteNonQuery();
            myconnection.Close();
          // BalUsers.UpdateDriver(Convert.ToInt32(TextnewNo.Text),TextChangeType.Text);
        }

如何获取值,并将其传递给查询
在此先感谢:)


解决方案

  HttpContext.Current.Request.QueryString [用户名];

 使用的Request.QueryString [0]

如果那是你传递的唯一参数。虽然不会跟着这一点,如果我是你。这将打破,如果你想传递的参数和放大器;更改在previous页面的顺序。

请注意:为了完成起见,我建议您加密为安全起见查询字符串

this is my code for the page through which I want to Pass the Value

protected void UpdateDriver(object sender, EventArgs e) 
        {
            Button btn = (Button)sender;
            GridViewRow gvr = (GridViewRow)btn.NamingContainer;
            HiddenField hid = (HiddenField)gvr.Cells[0].FindControl("hdnID");
            int UserID = Convert.ToInt32(hid.Value);
            String Url = "UpdateDriver.aspx?" + "UserID=" + UserID;
            Response.Redirect(Url);
           // BalUsers.UpdateDriver();
         //   HiddenField hid = (HiddenField)gridview1.Cells[0].FindControl("hdnID");
          //  BalUsers
        }

So at the update driver page i WANT to get the UserID and pass it to my CommandText

protected void Button1_Click(object sender, EventArgs e)
        {
            myconnection.Open();

            cmd.CommandText = "UPDATE [Ovms_New].[dbo].[tbl_driver] SET [lisenceNO] = ('@lisenceNO'),[liscenceType] = ('@liscenceType') WHERE (UserID = '@UserID')";
            cmd.ExecuteNonQuery();
            myconnection.Close();
          //  BalUsers.UpdateDriver(Convert.ToInt32(TextnewNo.Text), TextChangeType.Text);
        }

how to get that value and pass it to the query thanks In Advance :)

解决方案

HttpContext.Current.Request.QueryString["UserID"];

or

Use Request.QueryString[0] 

if thats the only parameter you're passing. Although won't follow this if I were you. This will break if you wanted to pass more parameters & change the order in the previous page.

Note: For the sake of completion, I would suggest you to encrypt the querystring for the sake of security.

这篇关于如何通过引用或URL获得previous页值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆