2017-03-22 10 views
0

私はビデオポータルのWebサイトで作業していますが、ほとんど完了しましたが、パフォーマンスに問題があります。つまり、ページの内容全体を読み込むのに時間がかかります。ajaxまたはjqueryを使用した部分ページの読み込み

すぐにページのヘッダーを読み込み、残りのコンテンツをajaxを使用して読み込みたいのですが、ここに私のウェブサイトへのライブリンクがあります。ここで enter link description here

私はページに

public partial class Index : System.Web.UI.Page 
    { 
     PlayListBLL _playList = new PlayListBLL(); 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      try 
      { 
       if (!IsPostBack) 
       { 
        bindRepeaters(); 
       } 
      } 
      catch (Exception) { } 
     } 

     private void bindRepeaters() //get news of all categoeries. 
     { 
      rp_top_story.DataSource = _playList.GetData(_playList._topStory).Take(8); 
      rp_top_story.DataBind(); 

      rp_national.DataSource = _playList.GetData(_playList._national).Take(8); 
      rp_national.DataBind(); 

      rp_sports.DataSource = _playList.GetData(_playList._sports).Take(8); 
      rp_sports.DataBind(); 

      rp_entertainment.DataSource = _playList.GetData(_playList._entertainment).Take(8); 
      rp_entertainment.DataBind(); 

      rp_international.DataSource = _playList.GetData(_playList._international).Take(8); 
      rp_international.DataBind(); 

      rp_science_technology.DataSource = _playList.GetData(_playList._scienceTechnology).Take(8); 
      rp_science_technology.DataBind(); 

      rp_smash_hit.DataSource = _playList.GetData(_playList._smashHits).Take(8); 
      rp_smash_hit.DataBind(); 

      rp_food_life_style.DataSource = _playList.GetData(_playList._foodLifeStyle).Take(8); 
      rp_food_life_style.DataBind(); 

      rp_capital_eye.DataSource = _playList.GetData(_playList._capitalEye).Take(8); 
      rp_capital_eye.DataBind(); 
     } 
    } 

をロードするために使用していたコードで実際に私は、リピータが結合する前に、ページのヘッダーを読み込むと、リピータは、AJAX呼び出しにバインドする必要があります。

答えて

1

私はこのコードが必要だと思います。

でも、画像を読み込む必要があります。 (このコードには含まれていません)

は、のリピータ数に使用する必要があります。

あなたのデータ読み込み速度が非常に遅いためです。

.aspxの

$.ajax({ 
    type: "POST", 
    url: "/Default.aspx/RequestControlString", 
    data: { }, 
    contentType: "application/json; charset=utf-8", 
    dataType : "json", 
    success: function (data) { 
     $("div").append(decodeURIComponent(data.d)); 
    } 
}); 

は.cs

[System.Web.Services.WebMethod] 
public static string RequestControlString() 
{ 
    TextWriter stringWriter = new StringWriter(); 
    HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); 
    var dt = new List<string>() { "1", "2", "3", "4" }; 
    var gridview = new GridView() { DataSource = dt }; 
    // you can replace this grid to usercontrol or repeater. 
    // i recommend usercontrol. 
    // because you have a style. 
    gridview.DataBind(); 
    gridview.RenderControl(htmlWriter); 
    string html = stringWriter.ToString(); 
    return html; 
} 
関連する問題