locked
Ajax Timer in Visual Web Part RRS feed

  • Question

  • I am developing a Visual Web Part which makes some checks and make actions like display controls or hide in Visual Web Part.

    according on some of SPWeb.Properties values changes.

     

    So I think about ASP.NET timer .

    and wraped it into An Update Panel ..,

    But it still refresh the whole page !

    Here is a code I found for :Creating a Visual Web Part with AJAX Behavior

    http://msdn.microsoft.com/en-us/gg620536

     

    and this one for :

    How to Use AJAX Timer 

    http://www.aspxcode.net/free-asp-net-ajax-source-code-c.aspx?Topics=How to Use AJAX Timer

     

    But when I try to Deploy them it still reload the page.

     

    Here is my code :

    <div id ="AjaxDiv">
    <asp:Timer ID="Timer1" runat="server" Enabled="true" ontick="Timer1_Tick">
    </asp:Timer>
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"  runat="server">
    
       <Triggers>
        <asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
                
       
       </Triggers>
        <ContentTemplate>
            <table cellpadding="0" cellspacing="0" class="style1">
                <tr>
                    <td class="style2">
                        <asp:ImageButton ID="linkImgNotification" runat="server" Height="40px" 
                            ImageUrl="~/_layouts/images/Notifications/Untitled2.png" Visible="False" 
                            Width="34px" />
                    </td>
                    <td class="style2">
                        <asp:ImageButton ID="linkImgNotification2" runat="server" Height="42px" 
                            ImageUrl="~/_layouts/images/Notifications/Untitled.png" Width="36px" />
                   </td>
                </tr>
            </table>
                <br />
        </ContentTemplate>
    </asp:UpdatePanel>
    

     


    thank u for help
    Monday, January 16, 2012 12:31 PM

Answers

  • The Timer needs to be inside of the update panel.  Also note that you won't be able to update (but you will be able to look at) the objects outside of the updatePanel.

    You will need to place the update panel such that all of the items that will need to be updated are inside of it, but that as few of the items that won't need to be updated are either.

    • Marked as answer by Qiao Wei Thursday, January 26, 2012 5:44 AM
    Monday, January 16, 2012 6:19 PM
  • I read this artecle.

     

    I solved it like the following using (Silverlight )

    Client Object Model .

     I made a timer using :

     System.Threading.Timer timer;  
    

    Then At for each Time ...,

    then go to server and excecute my code for each time..


    thank u for help
    Monday, January 30, 2012 6:45 AM

All replies

  • The Timer needs to be inside of the update panel.  Also note that you won't be able to update (but you will be able to look at) the objects outside of the updatePanel.

    You will need to place the update panel such that all of the items that will need to be updated are inside of it, but that as few of the items that won't need to be updated are either.

    • Marked as answer by Qiao Wei Thursday, January 26, 2012 5:44 AM
    Monday, January 16, 2012 6:19 PM
  • I am sorry .., I did not get what you mean ..

     

    How can I do it ?

    can you show me the correct way please ?


    thank u for help
    Monday, January 16, 2012 8:50 PM
  • select the markup for your timer

    cut that text

    move the cursor to inside of the UpdatePanel's content template

    paste the text

     

    Monday, January 16, 2012 8:59 PM
  • It dose not work ...

     

     Please see another solution


    thank u for help
    Tuesday, January 17, 2012 3:34 PM
  • "It doesn't work" doesn't mean much.  What does happen?  What exactly isn't doing what you expect it to?  Did you ensure that everything that needs to be updated is inside of the update panel, as I told you before (I'm guessing this isn't the case).

    Try stepping through the code with the debugger to see what it's doing.

    Wednesday, January 18, 2012 3:46 PM
  • Hi, try using the property ChildrenAsTriggers="true" for the update panel.
    Anil
    Wednesday, January 18, 2012 6:45 PM
  • Hi, try using the property ChildrenAsTriggers="true" for the update panel.
    Anil
    He manually specified the trigger as the timer, and it looks to me like he did it right, so that shouldn't be necessary.  I would also assume that the other two buttons aren't supposed to asynchronously postback, so adding the child as triggers would be bad for his purposes.
    Wednesday, January 18, 2012 7:56 PM
  • At Microsoft MSDN:

    Using the AJAX Update Panel in SharePoint

    http://msdn.microsoft.com/en-us/library/ff650218.aspx

     

    You want to use the AJAX UpdatePanel control on a SharePoint page or in a Web Part even though, by default, this control does not work with these standard SharePoint components because of differences in the postback mechanisms that are used by SharePoint and ASP.NET


    thank u for help
    Monday, January 30, 2012 6:39 AM
  • I read this artecle.

     

    I solved it like the following using (Silverlight )

    Client Object Model .

     I made a timer using :

     System.Threading.Timer timer;  
    

    Then At for each Time ...,

    then go to server and excecute my code for each time..


    thank u for help
    Monday, January 30, 2012 6:45 AM