用ajax异步请求一个块

使用用户控件,作为一个块,生成一段独立的html。

请求一个一般应用程序,在一般应用程序中加载读取用户控件,并给用户控件传值。

         Page page = new Page();
           
            div1 ctl = (div1)page.LoadControl("div1.ascx");
            ctl.Id = "1";//给用户控件传递参数
 
            page.Controls.Add(ctl);
            StringWriter writer = new StringWriter();
            HttpContext.Current.Server.Execute(page, writer, false);
            context.Response.Write(writer.ToString());


这样就可以异步请求一个块了。


这是老赵的博客中用用户控件生成的html的例子。
public class GetComments : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
 
        ViewManager<ItemComments> viewManager = new ViewManager<ItemComments>();
        ItemComments control = viewManager.LoadViewControl("~/ItemComments.ascx");
 
        control.PageIndex = Int32.Parse(context.Request.QueryString["page"]);
        control.PageSize = 3;
 
        context.Response.Write(viewManager.RenderView(control));
    }
 
    public bool IsReusable { ... }
} 

 

转载于:https://www.cnblogs.com/Tpf386/p/7608258.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值