我需要知道是否可以调用控件并从类中附加它的事件。我一直在研究互联网上的一些有价值的信息,但无济于事。下面简单说明了我打算实现的目标。
PAGE
protected void Page_Load(object sender, EventArgs e)
{
DynamicControls(IsPostBack);
}
public void DynamicControls(bool posting_back)
{
ControlHandler ch = new ControlHandler();
CreateTextbox(item.id, item.value, item.textMode, item.mandatoryInput, item.maxLength,int.Parse(item.rowNumber), int.Parse(item.colNumber), item.visible, item.autoPostBack,item.enable, table);
}
CLASS
public void CreateTextbox(String id, String value, String textMode, bool mandatoryInput
, String maxLength, int rowNumber, int colNumber, bool visible, bool autopostBack, bool enable, Table table)
{
TextBox tb = new TextBox();
tb.ID = id;
tb.Text = value == null ? "" : value;
tb.TextMode = textMode == null ? TextBoxMode.SingleLine : textMode.ToLower() == "multiline" ? TextBoxMode.MultiLine : TextBoxMode.SingleLine;
tb.MaxLength = maxLength == null ? 32500 : int.Parse(maxLength);
tb.Visible = visible;
tb.Style.Add("width", "80%");
tb.Enabled = enable;
tb.AutoPostBack = autopostBack;
tb.Font.Bold = true;
tb.ForeColor = System.Drawing.Color.Chocolate;
tb.TextChanged += new EventHandler(tb_TextChanged);
}
protected void tb_TextChanged(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
tb.Text = //some values or display in another control in the form
}
由于
答案 0 :(得分:0)
可以听取事件是的。虽然应始终在页面preinit或page init期间创建动态控件,但不要加载。