2011-06-16 20 views
0

こんにちは私は必要が生じた場合に通知をポップアップしたい。私は、新しいメッセージが到着したかどうかを調べるasp.netタイマーを使用しています。私が得ている問題は、jquery通知が表示されないということです。私はこれがアップデートパネルと関係があると推測しています。なぜなら、pageloadから呼び出そうとするとうまくいきました。ここに私のコードです。Jquery通知ポップアップ - jqueryとupdatepanels

protected void updateTimer_OnTick(object sender, EventArgs e) 
    { 
     Cache Cache = new Cache(); 

     users = Cache.getUserDetailsByUserID(Convert.ToInt32(Page.User.Identity.Name)); 

     if (users._bNewNotification) 
     { 
      List<UserNotification> listUserNotification = null; 

      listUserNotification = Cache.getLatestNotifcationsByUserID(Convert.ToInt32(Page.User.Identity.Name)); 

      foreach (UserNotification userNotification in listUserNotification) 
      { 
       StringBuilder jquery2 = new StringBuilder(); 

       jquery2.AppendLine("$.extend($.gritter.options, {"); 
       jquery2.AppendLine("position: 'bottom-left',"); 
       jquery2.AppendLine("fade_in_speed: 100,"); 
       jquery2.AppendLine("fade_out_speed: 100,"); 
       jquery2.AppendLine("time: 3000"); 
       jquery2.AppendLine("});"); 
       Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(), jquery2.ToString(), true); 

       StringBuilder jquery1 = new StringBuilder(); 
       jquery1.AppendLine(" var unique_id = $.gritter.add({"); 
       jquery1.AppendLine("  title: 'This is a sticky notice!',"); 
       jquery1.AppendLine("  text: '" + userNotification._NotificationType + "',"); 
       jquery1.AppendLine("  image: 'http://s3.amazonaws.com/twitter_production/profile_images/132499022/myface_bigger.jpg',"); 
       jquery1.AppendLine("  sticky: true,"); 
       jquery1.AppendLine("  time: '',"); 
       jquery1.AppendLine("  class_name: 'my-sticky-class'"); 
       jquery1.AppendLine(" });"); 
       Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(), jquery1.ToString(), true); 
      } 

      users._bNewNotification = false; 
      users.UpdateNewNotification(); 

      Cache.RemoveUserProfileCacheByUserID(users._USERS_ID); 
     } 
    } 

は、誰かがあなたのアプローチは機能しません

+0

Javascriptデバッガ/ブラウザコンソールでランタイムエラーをチェックしましたか? – foxy

+0

はい発生したエラーはありません。私は関数がロードされているファイルに依存していることを知っているので、私は再びjavascriptファイルをリロードする必要がありますか? – pmillio

答えて

2

、私はそれは私が間違っているのであるかを把握助けて感謝することはできます。ブラウザがあなたのページを取得すると、接続が切断されるので、サーバ側 C#タイマーイベントハンドラコードには、対話するブラウザがありません。

Webページのクライアントサイド JavaScriptでポーリングを実装するような何かをする必要があります。例えば

<script> 
$(document).ready(function(){ 
    window.setInterval(function(){ 
     $.get('path/to/GetNotifications.aspx', function(data){ 
      // data contains text from GetNotifications.aspx 
      // it could be JSON, XML, CSV... it's up to you 
      // do something with it here... 
     }) 
    },5000 /*5s*/) 
}) 
</script> 
+0

こんにちは、お返事ありがとうございます、私はその上に私のストリングビルダにあるjqueryを返そうとしています。 – pmillio

+0

私が言ったように:あなたのアプローチは動作しません。 ASPXページにクライアントサイドのポーリングコードを埋め込み、通知を取得する一種の「サービス」ページを作成するだけで済みます。 –

関連する問題