从页面值传递给用户控件 [英] Pass values from page to user control

查看:95
本文介绍了从页面值传递给用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主页面两个标签存储姓和名。我也有一个类的值(类没有做太多,但我使用他们的未来扩展)。我有一个用户控件,这将发送一封电子邮件,名字和姓氏的身上。

I am storing name and last name in two labels in main page. I also have those values in a class (class doesnt do much but i am using them for future expansion). I have a user control that will send an email with name and last name as body.

我的问题是,我怎么能转移标签或类变量值到用户控件的身体变量?

My question is that how can I transfer label or class variable values into user control's body variable?

推荐答案

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

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;}
      ...
    }

后来这在code后面的可分配像

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

myUserControl cntrl = new myUserControl();
    cntrl.myIntProperty = 5;

取而代之的是你可以通过标记值也喜欢

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

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

这篇关于从页面值传递给用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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