惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
WordPress大学
WordPress大学
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Last Watchdog
The Last Watchdog
AWS News Blog
AWS News Blog
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - Franky
L
Lohrmann on Cybersecurity
H
Heimdal Security Blog
GbyAI
GbyAI
The Hacker News
The Hacker News
Engineering at Meta
Engineering at Meta
F
Full Disclosure
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
S
Secure Thoughts
D
Docker
T
The Blog of Author Tim Ferriss
AI
AI
H
Help Net Security
L
LINUX DO - 热门话题
TaoSecurity Blog
TaoSecurity Blog
Y
Y Combinator Blog
B
Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
NISL@THU
NISL@THU
有赞技术团队
有赞技术团队
Schneier on Security
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Scott Helme
Scott Helme
小众软件
小众软件
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
J
Java Code Geeks
博客园 - 叶小钗
M
MIT News - Artificial intelligence
Cloudbric
Cloudbric
T
Troy Hunt's Blog
T
Tor Project blog
量子位
博客园 - 司徒正美

博客园 - Arishuang

数据类型 varchar 和 varchar 在 modulo 运算符中不兼容。 ASP.NET2.0_多语言本地化应用程序 ASP.NET2.0_缓存 ASP.NET中的状态管理功能详解(转载) [ASP.NET] Session 详解(转载) ASP.NET页面下载功能程序(转载) vs2005中“密码最短长度为7,其中必须包含以下非字母数字字符: 1”错误 (转载) ASP.NET中实现页面间的参数传递 QueryString\Application\Session\Cookie (转载) - Arishuang ASP.NET页面跳转的几种方法(转载) 常用正则表达式(转载) C#_解决在控制台中输入Ctrl+Z的问题 C#格式化输出(转载) C#格式化输出 面试题之金山_函数练习3_数值转换并输出数值中各个数字的个数(从低位到高位,输出转换后数值的各个数字个数) 面试题之金山(函数练习2)_字符排序(字母、数字及其它字符)ParseString DS_汉诺塔 XML_(3)_用C#操作缓存中的XML即DOM 观书后感之"NET Web Services:架构与实现 (美)贝列哲 "2008-5-2 下定决心,认定了,就全力以赴.Web应用程序开发--跟你杠上了
ASP.NET2.0_执行页面发送的强类型方法与弱类型方法
Arishuang · 2008-07-23 · via 博客园 - Arishuang

强类型方法.

     1,先在源页面代码块中,声明一个公共属性;

     2,再在宿页面呈现块中,添加一个<% PreviousPageType %>指令,在其中指定VirtualPath属性

     3,最后在宿页面代码块中,用PreviousPage直接调用源页面代码块的公共属性即可.

例子如下:

源页面

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Typed.aspx.cs" Inherits="Typed" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>强类型方法</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" AssociatedControlID="TextBox1" Text="姓名:"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" PostBackUrl="~/TestTyped.aspx"
            Text="完成" /></div>
    </form>
</body>
</html>

public partial class Typed : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string UserName
    {
        get
        {
           return this.TextBox1.Text.ToString();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}

宿页面

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            Response.Write(string.Format("欢迎{0}使用执行跨页面发送数据的强类型方法!", PreviousPage.UserName));
        }
    }

弱类型方法:

     1,在宿页面代码块中,用PreviousPage的FindControl方法得到相应的控件,再转换;

     2.最后调用此转换后的控件属性即可.

例子如下:

源页面

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Untyped.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>弱类型方法</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="姓名:" AssociatedControlID="TextBox1"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="完成"  PostBackUrl="~/TestUntyped.aspx" OnClick="Button1_Click"/></div>
    </form>
</body>
</html>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            TextBox txtName=(TextBox)PreviousPage.FindControl("TextBox1");
            Response.Write(string.Format("欢迎{0}使用执行跨页面发送数据的弱类型方法!",txtName.Text.ToString()));
        }
    }

宿页面

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            Response.Write(string.Format("欢迎{0}使用执行跨页面发送数据的强类型方法!", PreviousPage.UserName));
        }
    }