tags:

views:

1813

answers:

2

I have a page with two update panels each of which has a gridview generated dynamically. Updatepanel1 refreshes every ten seconds on a timer. The second update/grid refreshes when an item is selected in the first grid.

I'm trying to accomplish this feat using __doPostBack. This method does reach the server and run my .update on updatepanel2. I see that updatepanel2 gets data, but the form never actually updates updatepanel2.

I can get updatepanel2 to display data only when updatepanel1 timer ticks and I set updatepanel2 mode to "Always".

anyone have any suggestions?

Thanks

+1  A: 

Well I fixed this problem. I modified to using the following method for the doPostBack call.

http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/

Hope this helps.

DaVinciCoder
A: 

I see you answered your own question, but for the benefit of others, instead of doPostBack(), why not set both on a Timer to refresh at a specified interval, or as a Tick event method with an "UpdatePanel1.Update()" at the end of the method? For this way, you'd need to set the interval in the Default.aspx page code itself; I picked 10ms so it could show the progress for a very fast operation:

<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="360000" />
<asp:Button ID="btnDoSomething" runat="server" Text="Do Something" OnClick="btnDoSomething_Click" />
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load" UpdateMode="conditional"> 
    <ContentTemplate>
        <span id="spnLabel" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="10" OnTick="Timer1_Tick"></asp:Timer> 
    </ContentTemplate>         
    <Triggers >
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
 </asp:UpdatePanel> 

Then have a Timer1_Tick method in the code-behind that you call when you have an update - in this example, something to add to spnLabel.InnerHtml from a btnDoSomething_Click() method:

protected void btnDoSomething_Click(object sender, EventArgs e)
{
     Timer1.Enabled = true;
     Timer1.Interval = 10;
     Timer1_Tick(sender, e);
     Timer1.Enabled = false;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
     spnLabel.InnerHtml = "hi";
     UpdatePanel1.Update();
}

Remember that the refresh is controlled by the Timer interval, not by when you call Timer1_Tick(sender,e), even if you have an UpdatePanel1.Update() at the end - example, if you set the interval to 10000, it would update after 10 seconds, even if your operation had used the Timer1_Tick() method several times before then. You would still need an UpdatePanel1.Update() at the end, regardless, though.

-Tom

Tom Jackson

related questions