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

推荐订阅源

云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
博客园 - 司徒正美
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
博客园 - 聂微东

博客园 - 嚣张的沉默

读写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(); }
    }