当前位置:网站首页>ASP.NET 跨页面提交(Button控件页面重定向)
ASP.NET 跨页面提交(Button控件页面重定向)
2022-06-29 21:33:00 【八十八老】
新建web窗体
Cross1.aspx
Cross2.aspx
1、设置源页面Button控件的PostBackUrl属性设置为目标页面路径
PostBackUrl="~/Chap2/Cross2.aspx"
2、在目标页面头部添加**@PreviousPageType指令**,设置属性VirtualPath为源页面路径
<%@ PreviousPageTypeVirtualPath=="~/Chap2/Cross1.aspx"%>
Cross1.aspx完整代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cross1.aspx.cs" Inherits="Chap2_Cross1" %>
<!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">
<div>
用户名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
密码:<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="确认" PostBackUrl="~/Chap2/Cross2.aspx" />
</div>
</form>
</body>
</html>
3、在目标页面访问源页面数据的两种方法
利用公共属性获取值
利用控件属性获取值
关键代码
public string Name
{
get {
return txtName.Text; }
}
//利用公共属性获取值
lblMsg.Text = "用户名:" + PreviousPage.Name + "<br/>";
//利用控件属性获取值
TextBox txtPassword = (TextBox)PreviousPage.FindControl("txtPassword");
lblMsg.Text += "密码:" + txtPassword.Text;
Cross1.aspx.cs完整代码
public partial class Chap2_Cross1 : System.Web.UI.Page
{
public string Name
{
get {
return txtName.Text; }
}
}
Cross2.aspx完整代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cross2.aspx.cs" Inherits="Chap2_Cross2" %>
<%@ PreviousPageType VirtualPath="~/Chap2/Cross1.aspx" %>
<!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">
<div>
<asp:Label ID="lblMsg" runat="server" ></asp:Label>
</div>
</form>
</body>
</html>
Cross2.aspx.cs完整代码
using System;
using System.Web.UI.WebControls;
public partial class Chap2_Cross2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(PreviousPage.IsCrossPagePostBack)//判断是否为跨页面提交
{
//利用公共属性获取值
lblMsg.Text = "用户名:" + PreviousPage.Name + "<br/>";
//利用控件属性获取值
TextBox txtPassword = (TextBox)PreviousPage.FindControl("txtPassword");
lblMsg.Text += "密码:" + txtPassword.Text;
}
}
}


边栏推荐
- leetcode:724. 寻找数组的中心下标
- Selection of materials for space conductive disc slip ring
- PostgreSQL weekly news - June 22
- C. Most Similar Words
- Amazon Keyword Search API interface (item_search- Amazon product search interface by keyword), Amazon API interface
- 【ROS进阶篇】第二讲 自定义头、源文件封装
- 阿里巴巴店铺的所有商品API接口(item_search_shop-获得店铺的所有商品接口),阿里巴巴API接口
- Amazon Product details API interface - (item_get get Amazon Product details interface), Amazon details API interface
- Rsync method of establishing multi directory module
- Goahead translation - Active Server Pages
猜你喜欢

Golang operation etcd

数字密码锁verilog设计+仿真+上板验证

How to judge the quality of conductive slip ring from its appearance

Résumé du projet de petite bibliothèque

Small library project summary

一颗新的北极星已经升起!

CLI tool foundation of ros2 robot f1tenth

Autodesk Revit 2023 software installation package download and installation tutorial

Flame retardant test of aluminum sheet as/nzs 1530.1 non combustible materials

唯品会商品详情API接口(item_get-获得唯品会商品详情接口),唯品会详情API接口
随机推荐
CORDIC based Signal Processor desgn
Win10 add SSH public key
[cloud native] use of Nacos taskmanager task management
彩涂钢板密封板申请BS 476-3如何备样?
How to prepare samples for application of color coated steel sealing plates to BS 476-3?
Amazon Product details API interface - (item_get get Amazon Product details interface), Amazon details API interface
leetcode:370. Interval addition
Small library project summary
推荐书籍--白夜行
一次 Keepalived 高可用的事故,让我重学了一遍它!
STM32 minimum system construction (schematic diagram)
Knowledge distilling learning notes
About Effect Size
leetcode:370. 区间加法
How to judge the quality of conductive slip ring from its appearance
I want to register my stock account online. How do I do it? In addition, is it safe to open a mobile account?
Topic39——78. subset
Viewing technological changes through Huawei Corps (V): smart Park
Verilog implements DDS waveform generator module, which can realize adjustable frequency and phase, three waveforms