首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ITemplate类引用页/控件

从ITemplate类引用页/控件
EN

Stack Overflow用户
提问于 2013-08-29 21:29:09
回答 1查看 49关注 0票数 0

我有一个用户控件,其中我有一个动态模板字段的RadGrid -因为它们是动态的,所以我使用从ITemplate继承的我自己的自定义类。代码如下:

代码语言:javascript
复制
    public class ApplicationHeaderTemplateItem : ITemplate
    {
        private string colName;
        public ApplicationHeaderTemplateItem(string cName)
        {
            colName = cName;
        }

        public void InstantiateIn(Control container)
        {

            HtmlTable tb = new HtmlTable();
        HtmlTableRow headerRow = new HtmlTableRow();


        //Create the textbox to display the percentage
        HtmlTableCell percentCell = new HtmlTableCell();
        RadNumericTextBox txt = new RadNumericTextBox();
        txt.ID = "txt" + colName;
        txt.DataBinding += txt_DataBinding;
        txt.AutoPostBack = true;
        txt.TextChanged += txt_TextChanged;
        percentCell.Controls.Add(txt);
        headerRow.Cells.Add(percentCell);

         --snip--
        }

        void txt_TextChanged(object sender, EventArgs e)
        {

        }

    }

如您所见,我的textbox有一个TextChanged事件。我的问题是该方法是在ApplicationHeaderTemplateItem类的上下文中创建的,因此我无法访问用户控件中的任何控件。有什么办法可以做到这一点吗?

EN

回答 1

Stack Overflow用户

发布于 2013-08-29 21:39:15

使用sender参数来获取您的TextBox,因为每个控件都有一个Page property,所以您已经在那里了。

代码语言:javascript
复制
void txt_TextChanged(object sender, EventArgs e)
{
    Control txt = (Control) sender;
    Page page = txt.Page;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18512375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档