Trying to update gridview in updatepanel using jquery every n seconds

I would like to update the following gridview every 5 seconds. I thought I could use javascript to call the postback, which runs, but never hits the code behind. I tried mapping this to a button and calling the .click event, but that did not work either. I think I am close -- can someone nudge me along?

    <asp:UpdatePanel ID="udPanel2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <h3>Waiting to Sync</h3>
            <asp:LinkButton ID="lnkbtnRefreshXREF" runat="server" Text="Refresh" ToolTip="Refresh" CssClass="syncbtn"></asp:LinkButton>
            <asp:GridView ID="gvXREF" runat="server" GridLines="None" CssClass="gv" AlternatingRowStyle-CssClass="gvalt" AutoGenerateColumns="false" ShowHeaderWhenEmpty="true">
                <Columns>
                    <asp:BoundField HeaderText="Stop ID" DataField="STOP_ID" />
                    <asp:BoundField HeaderText="Customer ID" DataField="WHOLE_ACCOUNT_ID" />
                    <asp:BoundField HeaderText="Nickname" DataField="NICKNAME" />
                    <asp:BoundField HeaderText="Name" DataField="NAME" />
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

Open in new window


    <script>
        $(document).ready(function () {
            var t = 5
            if (t > 0) {
                // ### Start Page Reload Timer
                var iTimeRemaining = t;
                window.setInterval(function () {
                    if (iTimeRemaining == 0) {
                        //Post Back
                        setTimeout('__doPostBack(\'<%= lnkbtnRefreshXREF.ClientID%>\',\'\')', 0);
                    } else {
                        iTimeRemaining = iTimeRemaining - 1
                    }

                }, 1000);
            }
        });
    </script>

Open in new window


    Protected Sub lnkbtnRefreshXREF_Click(sender As Object, e As EventArgs) Handles lnkbtnRefreshXREF.Click
        PopulateLandmarkXREFGV()
    End Sub
jsmithrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BobHavertyComhCommented:
Is this code sending out data or does it simply need to be refreshed every few seconds?
0
jsmithrAuthor Commented:
Hi Bob,
Yes, this code actually binds sql data to the gridview:

Protected Sub lnkbtnRefreshXREF_Click(sender As Object, e As EventArgs) Handles lnkbtnRefreshXREF.Click
         PopulateLandmarkXREFGV() 
     End Sub 

Open in new window


    Private Sub PopulateLandmarkXREFGV()
        gvXREF.DataSource = objLMHelper.GetLandmarkXREF()
        gvXREF.DataBind()
    End Sub

Open in new window

0
BobHavertyComhCommented:
Right, but are you sending form data out with any sort of submit button on that page? If you only want the already bound data to be refreshed, rather than sent, then meta refresh will do that for you in one line of code. It sounds to me like these bound fields are only retrieving what is in a database. So if you are not sending info from that page, and just want to request and display info from a DB at a set interval, then meta refresh will do exactly that.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

jsmithrAuthor Commented:
I see what you are saying...
Yes, there are other functions on this page that the user submits. I did not include the entire markup for the page in this post.

I have another button on the page that submits form data to the server.
Did that answer your question?

So, I do not think meta refresh on the whole page will work.
- J
0
jsmithrAuthor Commented:
I found this article that uses and asp.net timer control. I have not tried to implement this, but will post my results when I do:

http://www.devcurry.com/2009/03/how-to-refresh-aspnet-gridview.html
0
jsmithrAuthor Commented:
Using the asp.net timer worked perfectly. Slap the whole thing inside an update panel and it works smoothly.

<h3>Auto Refresh Gridview</h3>
    <asp:UpdatePanel ID="updPanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Timer ID="tmrAutoRefreshTimer" runat="server" Interval="5000" OnTick="tmrAutoRefreshTimer_Tick"></asp:Timer>
            <asp:GridView ID="gvAutoRefresh" runat="server" CssClass="gv" GridLines="None" AlternatingRowStyle-CssClass="gvalt" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField HeaderText="ID" DataField="ApplicationID" ItemStyle-Width="25" ReadOnly="true" />
                    <asp:BoundField HeaderText="Message" DataField="AuditMessage" ReadOnly="true" />
                    <asp:BoundField HeaderText="Created" DataField="CreateDate" DataFormatString="{0:d}" ItemStyle-Width="100" ReadOnly="true" />
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.