我有一个用户控件,其中我有一个动态模板字段的RadGrid -因为它们是动态的,所以我使用从ITemplate继承的我自己的自定义类。代码如下:
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类的上下文中创建的,因此我无法访问用户控件中的任何控件。有什么办法可以做到这一点吗?
发布于 2013-08-29 21:39:15
使用sender参数来获取您的TextBox,因为每个控件都有一个Page property,所以您已经在那里了。
void txt_TextChanged(object sender, EventArgs e)
{
Control txt = (Control) sender;
Page page = txt.Page;
}https://stackoverflow.com/questions/18512375
复制相似问题