I am having some problems creating a asp textbox dynamically in a webservice and a ajax calendar extender. Is this possible to do. I did the example with the dynamic lable and that works fine, but when it comes to creating a textbox i get this error "Control 'txtSDate' of type 'TextBox' must be placed inside a form tag with runat=server"
here is my code.
[OperationContract]
public string LoadUserControl(string message,int id)
{
using (Page page = new Page())
{
UserControl userControl = (UserControl)page.LoadControl("/UserControls/BudgetItemTD.ascx");
(userControl.FindControl("lblBudgetName") as Label).Text = message;
(userControl.FindControl("lblBudgetName") as Label).ID = "lblBudgetName132";
(userControl.FindControl("txtSDate") as TextBox).Text = message;
(userControl.FindControl("txtSDate") as TextBox).ID = "txtStartDate99";
(userControl.FindControl("AjaxExtender") as AjaxControlToolkit.CalendarExtender).ID = "AjaxExtender99";
(userControl.FindControl("AjaxExtender99") as AjaxControlToolkit.CalendarExtender).TargetControlID = "txtStartDate99";
page.Controls.Add(userControl);
using (StringWriter writer = new StringWriter())
{
//page.Controls.Add(userControl);
HttpContext.Current.Server.Execute(page, writer,false);
return writer.ToString();
}
}
}