Home > Web Front-end > JS Tutorial > body text

js obtains UserControl content to provide convenience when spelling html_javascript skills

WBOY
Release: 2016-05-16 16:32:12
Original
1446 people have browsed it

I read Lao Zhao’s article today but couldn’t debug it.

Copy code The code is as follows:

[AjaxPro.AjaxMethod]
public string gethtml()
{

UcViewHelper viewManager = new UcViewHelper();
UserControl control = viewManager.LoadViewControl("~/uc/giftoutmodel.ascx");
string s=viewManager.RenderView(control);

return s;

}

public class UcViewHelper 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();

this.m_pageHolder.Controls.Add(control);
HttpContext.Current.Server.Execute(this.m_pageHolder, output, false);

return output.ToString();
}
}

class MyPage : Page
{
public override void VerifyRenderingInServerForm(Control control)
{
//if (control is GridView || control is UserControl)
//{
// return;
//}
//base.VerifyRenderingInServerForm(control);
}
}

Test passed.

If:

Copy code The code is as follows:

[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);
}

The reason is that it turns out that Lao Zhao’s code inherited Page and then used VerifyRenderingInServerForm to verify. Secondly, my code did not inherit Page and directly used VerifyRenderingInServerForm, so it would cause

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!