thanks for the tip. still, i got the same error:
"System.Web.HttpException: Control 'ctl00_Button1' of type 'Button' must be placed inside a form tag with runat=server."
im loading the control inside a dynamic js JQuery tab.
$.ajax({
type: "POST",
url: "TabLoader.asmx/LoadNewTab",
data: "{'fullname':'" + fullname +
"', 'id':'" + id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$(tabName).html(msg.d);
}
});
and for asmx:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
[Serializable]
public class TabLoader : System.Web.Services.WebService
{
private Page _page;
[WebMethod]
public string LoadNewTab(string fullname, string id)
{
_page = new Page();
UserControl ctl = LoadControl("~/controls/ctrlTabContent.ascx",
fullname,
Convert.ToInt32(id));
_page.Controls.Add(ctl);
StringWriter writer = new StringWriter();
HttpContext.Current.Server.Execute(_page,
writer,
false);
return writer.ToString();
}
private UserControl LoadControl(string userControlPath,
params object[] constructorParams)
{
List<Type> constParamTypes = new List<Type>();
foreach (object cp in constructorParams)
{
constParamTypes.Add(cp.GetType());
}
UserControl userCtrl = (UserControl)_page.LoadControl(userControlPath);
ConstructorInfo constructor = userCtrl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());
if (constructor == null)
throw new MemberAccessException("The requested constructor was not found on : " + userCtrl.GetType().BaseType.ToString());
else
constructor.Invoke(userCtrl, constructorParams);
return userCtrl;
}
}