1

当包含 asp(不是 html)控件的 Server.Execute() myusercontrol 我收到以下消息

在此处输入图像描述

用户控制:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyWebUserControl1.ascx.cs" Inherits="ImageHandlerClient.WebUserControl1" %>

堆栈跟踪:

 at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
4

1 回答 1

0

关于 Head runat="server",你可以试试这个:

public static string RenderView(string controlName)
{
    var pageHolder = new System.Web.UI.Page();
    var headHolder = new System.Web.UI.HtmlControls.HtmlHead();

    pageHolder.Controls.Add(headHolder);
    var formHolder = new System.Web.UI.HtmlControls.HtmlForm();
    pageHolder.Controls.Add(formHolder);

    // dynamically adding a script manager
    var sm = new System.Web.UI.ScriptManager();
    formHolder.Controls.Add(sm);


    var viewControl = pageHolder.LoadControl(controlName);

    formHolder.Controls.Add(viewControl);

    var output = new StringWriter();
    HttpContext.Current.Server.Execute(pageHolder, output, false);

    return output.ToString();
}

希望这会有所帮助

于 2013-05-14T15:18:42.763 回答