我只是試圖向SimpleQueryControl添加一些動態控件(當然這是一種Web控件並相應地繼承了所有的方法)。我不知道如何獲得我動態添加的Child控件的值。無法獲取動態添加的控件的ID(當然值)
class RoomPickerQueryControl : SimpleQueryControl
{
protected override void OnLoad(EventArgs e)
{
if (!Page.IsPostBack)
{
EnsureChildControls();
mColumnList.Visible = false;
}
}
protected override void OnInit(EventArgs e)
{
DateTimeControl controlStartDate = new DateTimeControl();
controlStartDate.LocaleId = 1053;
controlStartDate.CssClassTextBox = "ms-long";
controlStartDate.TimeZoneID = 1053;
controlStartDate.LocaleId = 1053;
controlStartDate.MinDate = DateTime.Now;
controlStartDate.ID = "startDateTime";
controlStartDate.Visible = true;
controlStartDate.Enabled = true;
controlStartDate.EnableViewState = true;
this.Controls.Add(controlStartDate);
base.OnInit(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
}
protected override int IssueQuery(string search, string groupName, int pageIndex, int pageSize)
{
//i'm unable to get the ids here
DateTimeControl dt = (DateTimeControl) FindControlRecursive(this, "startDateTime");
//i'm unable to get the ids here
DateTimeControl dt3 = (DateTimeControl)FindControlRecursive(this.Page, "startDateTime");
//i'm unable to get the ids here
DateTimeControl controlStartDate = (DateTimeControl)this.FindControl("startDateTime");
//i'm unable to get the ids here
DateTimeControl controlEndDate = (DateTimeControl)this.FindControl("endDateTime");
return rowCount;
}
public static Control FindControlRecursive(Control Root, string Id)
{
if (Root.ID == Id)
return Root;
foreach (Control Ctl in Root.Controls)
{
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
return FoundCtl;
}
return null;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
}
你想如何使用這個值? – EvgK 2011-02-07 16:33:04
我想在IssueQuery方法中使用DateTimeControl的值。 – 2011-02-07 16:34:31
請提供您的解決方案,您正在嘗試解決這些id和它的控件 – Luke 2011-02-07 16:41:09