[英]Dynamic Loading of ASP.NET Control using Handler Not working
Trying to dynamically load a user control into an aspx page using a custom handler. 尝试使用自定义处理程序将用户控件动态加载到aspx页面中。 I'm following the example from http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/ 我正在从http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/获取示例
public class AjaxUserControlHandler : AjaxControlHandler
{
public override Control GetControl(HttpContext context)
{
// Get the path to the user control
string path = context.Request.Url.LocalPath;
using (var page = new Page())
{
var viewControl = page.LoadControl(path) as UserControl;
return viewControl;
}
}
}
using System.Web;
using System.Web.UI;
public class AjaxUserControlHandler : AjaxControlHandler
{
public override Control GetControl(HttpContext context)
{
// Get the path to the user control
string path = context.Request.Url.LocalPath;
using (var page = new Page())
{
var viewControl = page.LoadControl(path) as UserControl;
return viewControl;
}
}
}
using System;
using System.ComponentModel;
public class AjaxEnabledAttribute : Attribute
{
[DefaultValue(RequestMethodSupport.All)]
public RequestMethodSupport Method { get; set; }
}
public enum RequestMethodSupport
{
All,
GET,
POST
}
My Welcome Portlet is 我的欢迎Portlet是
[AjaxEnabled]
public partial class WelcomePortlet : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
In my Web.Config 在我的Web.Config中
<httpHandlers>
<remove verb="*" path ="*.ascx"/>
<add verb="*" path="*.ascx" type="AjaxUserControlHandler"/>
</httpHandlers>
In my aspx page. 在我的aspx页面中。
$("#placeholder").load("Controls/WelcomePortlet.ascx");
But the control isnt loaded. 但是控件未加载。 I put break points in the AjaxUserControlHandler and AjaxUserControlHandler and the code doesn't get run. 我将断点放在AjaxUserControlHandler和AjaxUserControlHandler中,并且代码无法运行。
Note: AjaxControlHandler, AjaxEnabledAttribute and AjaxUserControlHanlder are in the App_Code folder and have been marked as Compile instead of Content. 注意:AjaxControlHandler,AjaxEnabledAttribute和AjaxUserControlHanlder在App_Code文件夹中,并被标记为Compile而不是Content。
What am I missing? 我想念什么?
Thanks. 谢谢。
What version of IIS are you using? 您正在使用哪个版本的IIS? You also need to configure IIS handler mappings or WebServer section in your Web.config. 您还需要在Web.config中配置IIS处理程序映射或WebServer部分。
https://msdn.microsoft.com/en-us/library/bb515343(v=vs.140).aspx http://www.iis.net/learn/develop/runtime-extensibility/developing-iis-modules-and-handlers-with-the-net-framework https://msdn.microsoft.com/zh-cn/library/bb515343(v=vs.140).aspx http://www.iis.net/learn/develop/runtime-extensibility/developing-iis-modules-和处理者与网络框架
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.