Reputation: 2127
I have created the Textbox and using CalendarExtener dynamically. I am getting the error"The TargetControlID of 'CalendarExtender1' is not valid. A control with ID 'text1' could not be found."
The below is my code
protected void Page_Load(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.ID = "text1";
AjaxControlToolkit.CalendarExtender publishdate = new AjaxControlToolkit.CalendarExtender();
publishdate.ID = "CalendarExtender1";
publishdate.TargetControlID = tb.ID;
Panel1.Controls.Add(publishdate);
}
Upvotes: 2
Views: 2320
Reputation: 460048
You haven't added the TextBox
to the page's control collection.
Panel1.Controls.Add(tb);
Panel1.Controls.Add(publishdate);
Can i ask why you want to create it dynamically? That will make things much more difficult than adding declaratively and might cause issues with events or ViewState.
Upvotes: 2