2011-09-14 12 views
0

私は、ページに2つのセクション、左セクションと右セクションを持っています。いずれかのAJAXタイマーが起動すると、JQueryが再実行されます

左セクションは条件付きの更新パネルにあり、Timer1に依存しています。

右側のセクションは、条件付きの更新パネルにあり、タイマ2

右側のセクションは、jQueryの画像サイクルを有するに依存しています。 Timer 1が起動しても、JQueryのピクチャサイクルはリフレッシュされます。これは、JQueryコードが更新パネルと相対的でなく、更新パネルの外に登録されるためです(物理コードが更新パネル内にあっても)。

私は左セクションとは異なる頻度で右セクションの更新をしようとしていますが、左セクションはJQueryを使用して右セクションをリフレッシュしています。ここで

は、支持コードです:

<div style="float:left; width:965px; height:1080px; background:White url(App_Themes/TheNest/images/TV/Daily-Specials.jpg) no-repeat 0 0; overflow:hidden;"> 
     <!-- Daily Specials --> 
     <div style="margin-left:25px; margin-top:295px; margin-bottom:10px; margin-right:10px;"> 
     <span style="float:right; color:White; font-size:45px;"><%=clsNaitsa.GetMonth(dTodaysDate.Month)%> <%=dTodaysDate.Day%>, <%=dTodaysDate.Year%></span> 
     <div style="clear:both; margin-bottom:100px;"></div> 
      <div style="overflow:hidden; height:685px;"> 
       <div id="Specials"> 
       <asp:UpdatePanel runat="server" id="UpdatePanel1" UpdateMode="Conditional"> 
        <ContentTemplate> 
        <asp:Timer runat="server" id="Timer1" Interval="10000" OnTick="Timer1_Tick"></asp:Timer> 
        <asp:Label ID="Label1" runat="server" Text="No Refresh Yet"></asp:Label> 
        <ul class="DailySpecials"> 
         <asp:PlaceHolder ID="ph_Specials" runat="server"></asp:PlaceHolder> 
        </ul>       
        </ContentTemplate> 
       </asp:UpdatePanel> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div style="float:left; width:955px; height:1080px; overflow:hidden;"> 
    <asp:UpdatePanel runat="server" id="UpdatePanel2" UpdateMode="Conditional"> 
     <ContentTemplate> 
     <asp:Timer runat="server" id="Timer2" Interval="25000" OnTick="Timer2_Tick"></asp:Timer> 
     <asp:Label ID="Label2" runat="server" Text="No Refresh Yet"></asp:Label> 
     <div class="pics"> 
       <img src="App_Themes/TheNest/images/TV/Pirate-tv-ad.jpg" alt="Pirate Boat Party" /> 
       <img src="App_Themes/TheNest/images/TV/Elections-tv-ad.jpg" alt="Senate and Student Services Elections" /> 
       <img src="App_Themes/TheNest/images/TV/Top-Model-TV-ad.jpg" alt="NAITSA's Next Top Model" /> 
       <img src="App_Themes/TheNest/images/TV/Sponsor-Thank-You.jpg" alt="Sponsors Thank-You" /> 
     </div> 
      <script type="text/javascript" language="javascript"> 
      //WILL RUN DURING ASYNC POST-BACKS 
      function pageLoad() { 
       $('.pics').unbind(); 
       $('.pics').cycle({ 
        fx: 'fade', 
        timeout: 5000, 
        speed: 1000 
       }); 
      }  

     // WILL RUN ONCE DURING INITIALIZATION - ASYNC POST-BACKS WILL NOT RUN AGAIN AND CYCLE BREAKS 
     //  $(document).ready(function() { 
     //   $('.pics').cycle({ 
     //   fx: 'fade', 
     //   timeout: 5000, 
     //   speed: 1000 
     //   }); 
     //  }); 
      </script>   
     </ContentTemplate> 
    </asp:UpdatePanel> 
    </div> 

//CODE BEHIND 
    protected void Page_Load(object sender, EventArgs e) 
{   
    ScriptManager1.RegisterAsyncPostBackControl(Timer1); 
    ScriptManager1.RegisterAsyncPostBackControl(Timer2); 

    dTodaysDate = DateTime.Now; 
    if(!Page.IsPostBack) 
     LoadSpecials(); 
} 

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    UpdatePanel1.Update(); 
    Label1.Text = DateTime.Now.ToString(); 
    LoadSpecials(); 
} 

protected void Timer2_Tick(object sender, EventArgs e) 
{   
    UpdatePanel2.Update(); 
    Label2.Text = DateTime.Now.ToString();   
} 

答えて

1

非同期ポストバックがこの経由で起きているときは、検出することができます:

function pageLoad(sender, e) { 
    if (!e.get_isPartialLoad()) { 
    //Do one time task 
    } 
} 

をただし、パネルが更新され、更新を決定するために、クライアントから面白いかもしれません-側。これを確認し、サイクルプラグインを呼び出すことができます。また、あなたは別の方法でプラグインのコードを置くことができます:

function cycle() { 
    $('.pics').unbind(); 
       $('.pics').cycle({ 
        fx: 'fade', 
        timeout: 5000, 
        speed: 1000 
       }); 
} 

そして、それをサーバーから呼び出してみてください。

ScriptManager.RegisterStartupScript(.., "cycle();"); 

場合は、適切なタイマーが発生します。

+0

おかげで、私は2番目の提案を使用し、それが魅力のように働きました。私はすべての人が見るために修正された解決策のコードで答えました。 – Mausimo

0

返信いただきありがとうございます。私は実際にはe.get_isPartialLoad()を理解していない。なぜなら、私はJavaScriptをたくさん使っていないので(もっと多くのJavaを学ぼうとしている)asp.netの更新パネルイベントを調べる方法がわからないからです。

しかし、私はあなたの2番目の答えを理解しています。これは素晴らしいです。私のJQueryサイクルをpageLoad()またはDocument.Ready()で行うのではなく、それ自身の関数ですべての問題を解決します:)サイクルがページ固有の関数ではないので、私はいつでも呼び出すか再初期化できます。いつでも部分的なポストバック中に呼び出されることはありません。ここで

右側のセクションにのみjQueryの時にタイマ2火災に再起動します今、私が使用した溶液と私の修正コードです:

<script type="text/javascript" language="javascript">  
function cycle() { 
    $('.pics').unbind(); 
    $('.pics').cycle({ 
     fx: 'fade', 
     timeout: 5000, 
     speed: 1000 
    }); 
}   
</script> 

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
<div style="width:1920px; height:1080px; overflow:hidden;"> 
    <div style="float:left; width:965px; height:1080px; background:White url(App_Themes/TheNest/images/TV/Daily-Specials.jpg) no-repeat 0 0; overflow:hidden;"> 
     <!-- Daily Specials --> 
     <div style="margin-left:25px; margin-top:295px; margin-bottom:10px; margin-right:10px;"> 
     <span style="float:right; color:White; font-size:45px;"><%=clsNaitsa.GetMonth(dTodaysDate.Month)%> <%=dTodaysDate.Day%>, <%=dTodaysDate.Year%></span> 
     <div style="clear:both; margin-bottom:100px;"></div> 
      <div style="overflow:hidden; height:685px;"> 
       <div id="Specials"> 
       <asp:UpdatePanel runat="server" id="UpdatePanel1" UpdateMode="Conditional"> 
        <ContentTemplate> 
        <asp:Timer runat="server" id="Timer1" Interval="5000" OnTick="Timer1_Tick"></asp:Timer> 
        <asp:Label ID="Label1" runat="server" Text="No Refresh Yet"></asp:Label> 
        <ul class="DailySpecials"> 
         <asp:PlaceHolder ID="ph_Specials" runat="server"></asp:PlaceHolder> 
        </ul>       
        </ContentTemplate> 
       </asp:UpdatePanel> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div style="float:left; width:955px; height:1080px; overflow:hidden;"> 
    <asp:UpdatePanel runat="server" id="UpdatePanel2" UpdateMode="Conditional"> 
     <ContentTemplate> 
     <asp:Timer runat="server" id="Timer2" Interval="15000" OnTick="Timer2_Tick"></asp:Timer> 
     <asp:Label ID="Label2" runat="server" Text="No Refresh Yet"></asp:Label> 
     <div class="pics"> 
       <img src="App_Themes/TheNest/images/TV/Pirate-tv-ad.jpg" alt="Pirate Boat Party" /> 
       <img src="App_Themes/TheNest/images/TV/Elections-tv-ad.jpg" alt="Senate and Student Services Elections" /> 
       <img src="App_Themes/TheNest/images/TV/Top-Model-TV-ad.jpg" alt="NAITSA's Next Top Model" /> 
       <img src="App_Themes/TheNest/images/TV/Sponsor-Thank-You.jpg" alt="Sponsors Thank-You" /> 
     </div> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
    </div> 
</div> 

protected void Page_Load(object sender, EventArgs e) 
{   
    ScriptManager1.RegisterAsyncPostBackControl(Timer1); 
    ScriptManager1.RegisterAsyncPostBackControl(Timer2); 

    dTodaysDate = DateTime.Now; 
    if (!Page.IsPostBack) 
    { 
     Page page = (Page)HttpContext.Current.CurrentHandler; 
     ScriptManager.RegisterStartupScript(page, this.GetType(), "JQueryCycle", "cycle();" ,true); 
     LoadSpecials(); 

    } 
} 

protected void Timer1_Tick(object sender, EventArgs e) 
{ 
    UpdatePanel1.Update(); 
    Label1.Text = DateTime.Now.ToString(); 
    LoadSpecials(); 
} 

protected void Timer2_Tick(object sender, EventArgs e) 
{  
    UpdatePanel2.Update(); 
    Label2.Text = DateTime.Now.ToString(); 
    Page page = (Page)HttpContext.Current.CurrentHandler; 
    ScriptManager.RegisterStartupScript(page, this.GetType(), "JQueryCycle", "cycle();", true);  
} 
関連する問題