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

推荐订阅源

P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
腾讯CDC
人人都是产品经理
人人都是产品经理
小众软件
小众软件
V
Visual Studio Blog
S
Secure Thoughts
J
Java Code Geeks
V
V2EX
量子位
The Hacker News
The Hacker News
酷 壳 – CoolShell
酷 壳 – CoolShell
Security Latest
Security Latest
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tailwind CSS Blog
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
T
Tenable Blog
S
Security @ Cisco Blogs
月光博客
月光博客
雷峰网
雷峰网
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
C
Cybersecurity and Infrastructure Security Agency CISA
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
Attack and Defense Labs
Attack and Defense Labs
博客园 - 三生石上(FineUI控件)
Hacker News - Newest:
Hacker News - Newest: "LLM"
有赞技术团队
有赞技术团队
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
TaoSecurity Blog
TaoSecurity Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
K
Kaspersky official blog

博客园 - 嚣张的沉默

读写txt文档 限制TextBox输入字数 计算TextBox输入的字数 我常用的正则与SQL语句 DataSet导入到Excel 年月日联动的JS代码 Repeater模板列 asp.net的几个小技巧 百叶窗效果 建站安全 倒计时代码 解决SQL2000安装服务器挂起 删除.NET的最近项目 屏幕右下角弹出广告 DataSet写入、导出XML 上传图片重命名并创建文件夹 自动跳转页面带参数 微软出的AJAX控件的安装(转载) 第一次开博
用户控件的传值方法
嚣张的沉默 · 2008-01-22 · via 博客园 - 嚣张的沉默

1、web页上输入信息,在用户控件上显示信息的方法:
新建一个网页,取名a.aspx

<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
        
    
</div>
    
</form>
</body>

a.apsx.cs

protected void Button1_Click(object sender, EventArgs e)
    
{

        Label Label1 
= (Label)WebUserControl1.FindControl("Label1");
        Label1.Text 
= TextBox1.Text;

    }

WebUserControl.aspx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

把用户控件拖到a.aspx上运行即可

2、输入框在页面上,按钮与标签在用户控件里
新建网页PageA.aspx

<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
<br />
        
<uc1:UcA id="UcA1" runat="server">
        
</uc1:UcA></div>
    
</form>
</body>

PageA.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    
{
        ((Button)UcA1.FindControl(
"Button1")).Click += new EventHandler(PMS_PageA_Click);
    }


    
void PMS_PageA_Click(object sender, EventArgs e)
    
{
        UcA1.Label1Text 
= TextBox1.Text;
    }

UcA.ascx

protected void Page_Load(object sender, EventArgs e)
    
{

    }


    
public string Label1Text
    
{
        
get return Label1.Text; }
        
set { Label1.Text = value.ToString(); }
    }