将标签控制从aspx页面传递到ascx页面 [英] pass label control from aspx page to ascx page

查看:58
本文介绍了将标签控制从aspx页面传递到ascx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将ASPX页面中标签的值(ID或文本)传递给Web用户控件(ASCX)页面?

带有代码的答案非常受欢迎。







How do i pass the value (ID or text) of a label in a ASPX page to "Web User Control(ASCX)" page?
Answers with code are highly appreciated.



<%@ Register Src="~/MYA/test_web.ascx" TagPrefix="uc1" TagName="test_web" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">

 <uc1:test_web  runat="server" ID="test_web" />

    <asp:TextBox runat="server" ID="test" OnTextChanged="test_TextChanged"></asp:TextBox>
</asp:Content>









我想要test_web.ascx页面中的文本框值。我该怎么办?



提前致谢





I want the textbox value in the test_web.ascx page. How shall i proceed?

Thanks in advance

推荐答案

在你的用户控件上创建一个属性要传递给它的数据的数据类型,并在创建控件时将其填充到页面中。



Create a property on your user control with the datatype of the data you want to pass to it, and populate it in your page on creation of the control.

public class myUserControl : Control
    {
      ...
      public int myIntProperty {get; set;}
      ...
    }



稍后在后面的代码中您可以分配值,例如




Later this in the code behind you can assign the value like

myUserControl cntrl = new myUserControl();
    cntrl.myIntProperty = test.text;



而不是这个你可以通过Markup传递值也像


Instead of this you can pass the value through Markup also like

<uc1:myUserControl ID="uc1" runat="server" myIntProperty="5" />


这篇关于将标签控制从aspx页面传递到ascx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆