0
컨트롤을 호출하고 클래스의 이벤트를 첨부 할 수 있는지 알아야합니다. 나는 귀중한 정보를 얻기 위해 인터넷을 연구했지만 아무 소용이 없다. 다음은 내가 성취하고자하는 것을 보여주는 간단한 그림입니다.별도의 클래스에서 동적 컨트롤 호출
페이지
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
}
감사
감사합니다. Brian. 제가 어떻게 그것을 성취 할 수 있는지에 대한 간단한 그림을 제게 주시겠습니까? – Jay
init에 대한 DynamicControls() 메서드 호출 이동 –