如何通过修改URL实现ASP.NET页面长尾词参数传递?
- 内容介绍
- 文章标签
- 相关推荐
本文共计552个文字,预计阅读时间需要3分钟。
这里,通过假设数据,手动创建一个类,然后创建一个集合,将其放入下拉框中,选择一个值后,会在另一个页面生成对应id的响应类:
csharpusing System;using System.Collections.Generic;
public class CustomClass{ // 类的属性和方法}
public class ResponseClass{ // 响应类的属性和方法}
public static void Main(){ // 创建一个下拉框 ComboBox comboBox=new ComboBox();
// 创建一个集合 List customClasses=new List();
// 添加数据到集合 customClasses.Add(new CustomClass()); // ... 添加更多类
// 将集合添加到下拉框 comboBox.DataSource=customClasses;
// 选择值后,创建响应类 comboBox.SelectedIndexChanged +=(sender, e)=> { CustomClass selectedClass=comboBox.SelectedItem as CustomClass; if (selectedClass !=null) { ResponseClass responseClass=new ResponseClass(); // ... 创建响应类 } };}
这里,通过假数据,手动创建的一个类,然后创建的一个集合,放入下拉框,选好值以后,点确定
会在另一个页面产生对应的id
创建一个类:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1 { public class Dept { public int Id { get; set; } public string DeptName { get; set; } } }
一个选择的web窗体
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dept.aspx.cs" Inherits="WebApplication1.Dept1" %> <!DOCTYPE html> <html xmlns="www.w3.org/1999/xhtml"> <head runat="server"> <meta 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"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> </form> </body> </html>
显示的web窗体的后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class DeptDetail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //直接通过request获取Module存入的id this.TextBox1.Text = $"{Request.QueryString["deptid"]}"; } } } }
效果图
选择一个后点击查询
地址栏和内容都进行了更改
到此这篇关于ASP.NET通过更改Url进行页面传值的文章就介绍到这了,更多相关asp.net url 页面传值内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!
本文共计552个文字,预计阅读时间需要3分钟。
这里,通过假设数据,手动创建一个类,然后创建一个集合,将其放入下拉框中,选择一个值后,会在另一个页面生成对应id的响应类:
csharpusing System;using System.Collections.Generic;
public class CustomClass{ // 类的属性和方法}
public class ResponseClass{ // 响应类的属性和方法}
public static void Main(){ // 创建一个下拉框 ComboBox comboBox=new ComboBox();
// 创建一个集合 List customClasses=new List();
// 添加数据到集合 customClasses.Add(new CustomClass()); // ... 添加更多类
// 将集合添加到下拉框 comboBox.DataSource=customClasses;
// 选择值后,创建响应类 comboBox.SelectedIndexChanged +=(sender, e)=> { CustomClass selectedClass=comboBox.SelectedItem as CustomClass; if (selectedClass !=null) { ResponseClass responseClass=new ResponseClass(); // ... 创建响应类 } };}
这里,通过假数据,手动创建的一个类,然后创建的一个集合,放入下拉框,选好值以后,点确定
会在另一个页面产生对应的id
创建一个类:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1 { public class Dept { public int Id { get; set; } public string DeptName { get; set; } } }
一个选择的web窗体
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dept.aspx.cs" Inherits="WebApplication1.Dept1" %> <!DOCTYPE html> <html xmlns="www.w3.org/1999/xhtml"> <head runat="server"> <meta 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"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> </form> </body> </html>
显示的web窗体的后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class DeptDetail : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //直接通过request获取Module存入的id this.TextBox1.Text = $"{Request.QueryString["deptid"]}"; } } } }
效果图
选择一个后点击查询
地址栏和内容都进行了更改
到此这篇关于ASP.NET通过更改Url进行页面传值的文章就介绍到这了,更多相关asp.net url 页面传值内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

