jqueryを使用してusercontrolをロードする必要があります。私はハンドラクラスを作成し、それを通してusercontrolをロードしました。 jqueryの一部です:Jqueryジェネリックハンドラを使用してusercontrolをロードする
$.ajax({
type: "POST",
url: "HandlerAdminManageDataSideMenu.ashx",
contentType: "application/html; charset=utf-8",
dataType: "html",
success: function (data) {
alert("success" + data);
$(".admin_side_menu").append(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
alert("Error Occured!");
}
});
マイハンドラファイルは次のようになります。
Public Class HandlerAdminManageDataSideMenu
Implements System.Web.IHttpHandler, IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World!")
context.Response.ContentType = "text/html"
context.Response.Write(RenderPartialToString("Shared\AdminManageDataSideMenu.ascx"))
End Sub
Private Function RenderPartialToString(ByVal controlName As String) As String
Dim page As New Page()
Dim control As Control = page.LoadControl(controlName)
page.Controls.Add(control)
Dim writer As New StringWriter()
HttpContext.Current.Server.Execute(page, writer, False)
Return writer.ToString()
End Function
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
ラインHttpContext.Current.Server.Execute(page, writer, False)
をエラーがスローされます:
Error executing child request for handler 'System.Web.UI.Page'
誰もがこの上で私を助けることができますか?
http://stackoverflow.com/a/491233/335105これがあなたの問題を解決するかどうかを確認してください – Rafay
は解決策を見つけることができませんでした –