zoukankan      html  css  js  c++  java
  • asp.net 将页面HTML化,通过Ajax请求返回到窗户端

    Ajax请求的WebService方法:

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class PagingService  : System.Web.Services.WebService {
    
        [WebMethod]
        public string GetPagingData(int page)
        {
            ViewManager<PagingData> viewManager = new ViewManager<PagingData>();
            var control = viewManager.LoadViewControl("~/PagingData.ascx");
    
            control.PageIndex = page;
    
            return viewManager.RenderView(control);
        }
    }
    public class ViewManager<T> where T : UserControl
    {
        private Page m_pageHolder;
    
        public T LoadViewControl(string path)
        {
            this.m_pageHolder = new Page();
            return (T)this.m_pageHolder.LoadControl(path);
        }
    
        public string RenderView(T control)
        {
            StringWriter output = new StringWriter();
    
            this.m_pageHolder.Controls.Add(control);
            HttpContext.Current.Server.Execute(this.m_pageHolder, output, false);
    
            return output.ToString();
        }
    }
    PagingData.ascx控件
    View Code
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PagingData.ascx.cs" Inherits="PagingData" %>
    
    <asp:Repeater runat="server" ID="Repeater1">
        <ItemTemplate>
            <%# Container.DataItem %>
        </ItemTemplate>
        <SeparatorTemplate>
            <br />
        </SeparatorTemplate>
        <FooterTemplate>
            <br />
        </FooterTemplate>
    </asp:Repeater>
    PagingData.ascx.cs
    View Code
    public partial class PagingData : System.Web.UI.UserControl
    {
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
    
            List<int> values = new List<int>();
            for (int i = (this.PageIndex - 1) * 5 + 1; i <= this.PageIndex * 5; i++)
            {
                values.Add(i);
            }
    
            this.Repeater1.DataSource = values;
            this.Repeater1.DataBind();
        }
    
        public int PageIndex { get; set; }
    }
  • 相关阅读:
    Python超级篇-机器学习
    python高给篇-爬虫
    机器学习之-sklearn
    luogu3384 【模板】树链剖分
    bzoj3884 上帝与集合的正确用法
    luogu2765 魔术球问题
    poj2976 Dropping tests 01分数规划
    luogu2764 最小路径覆盖问题
    luogu2763 试题库问题
    luogu2762 太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/you000/p/2834896.html
Copyright © 2011-2022 走看看