分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

ASP.NET页面之间传值的方式之QueryString(超详细)

发布时间:2023-09-06 01:18责任编辑:蔡小小关键词:.NET

QueryString

Querystring也叫查询字符串,这种页面间传递数据是利用网页地址URL。如果要从A页面跳转到B页面,则可以用Request.Redirect(”B.aspx?参数名=参数值”);在页面跳转后用Ruquest[“参数名”]来接收参数。这种方法使用简单,不用服务器资源。但是很容易被篡改且不能传递对象,只有在通过URL 请求页时查询字符串才是可行的。

  这种方法的优点:1.使用简单,对于安全性要求不高时传递数字或是文本值非常有效。
  这种方法的缺点:1.缺乏安全性,由于它的值暴露在浏览器的URL地址中的。
          2.不能传递对象。

  使用方法:1.在源页面的代码中用需要传递的名称和值构造URL地址。
       2.在源页面的代码用Response.Redirect(URL);重定向到上面的URL地址中。
       3.在目的页面的代码使用Request.QueryString["name"];取出URL地址中传递的值。

       例子:(1)a.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="a.aspx.cs" Inherits="Web.a" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> ???<title></title></head><body> ???<form id="form1" runat="server"> ???????<asp:Label ID="Label1" runat="server" Text="张君宝"></asp:Label> ???????<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> ???</form></body></html>

           (2)a.aspx.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Web{ ???public partial class a : System.Web.UI.Page ???{ ???????protected void Page_Load(object sender, EventArgs e) ???????{ ???????} ???????protected void Button1_Click(object sender, EventArgs e) ???????{ ???????????????????????var url = "b.aspx?name=" + Label1.Text; ???????????Response.Redirect(url);//点击Button按钮重定向到b页面 ???????} ???}}

       (3)b.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="b.aspx.cs" Inherits="Web.b" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> ???<title></title></head><body> ???<form id="form1" runat="server"> ???????<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> ???</form></body></html>

    (4)b.aspx.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Web{ ???public partial class b : System.Web.UI.Page ???{ ???????protected void Page_Load(object sender, EventArgs e) ???????{ ???????????Label1.Text= Request.QueryString["name"]; ???????} ???}}

  

ps:此文章是本人参考网上内容加上自己的理解整合而成,如无意中侵犯了您的权益,请与本人联系。

ASP.NET页面之间传值的方式之QueryString(超详细)

原文地址:http://www.cnblogs.com/kudsu/p/7694637.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved