UcViewHelper<UserControl> viewManager = new UcViewHelper<UserControl>(); UserControl control = viewManager.LoadViewControl("~/uc/giftoutmodel.ascx"); string s=viewManager.RenderView(control);
return s;
}
public class UcViewHelper<T> where T : UserControl { private MyPage m_pageHolder; public T LoadViewControl(string path) { m_pageHolder = new MyPage(); return (T)m_pageHolder.LoadControl(path); } public string RenderView(T control) { StringWriter output = new StringWriter();
[AjaxPro.AjaxMethod] public string gethtml() { string s = getString(); return s;
} public string getString() { UserControl control = LoadControl("~/uc/giftoutmodel.ascx") as UserControl; StringWriter tw = new StringWriter(); HtmlTextWriter writer = new HtmlTextWriter(tw); control.RenderControl(writer); return writer.InnerWriter.ToString(); }
public override void VerifyRenderingInServerForm(Control control) { // if (control is GridView || control is UserControl) // { // return; //} //base.VerifyRenderingInServerForm(control); }