用HttpContext获得Server对象,然后执行Execute方法,看代码:

 

public string RenderView(UserControl control)
{
   Page page
=new Page();
   Form form
=new Form();

   page.Controls.Add(form);
   StringWriter output 
= new StringWriter();
 
   form.Controls.Add(control);
   HttpContext.Current.Server.Execute(page, output, 
false);
 
   
return output.ToString();
}

 

如果是不需要在Form中的控件,我们可以省去添加Form这一步。

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2021-05-08
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案