• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

ASP.net AJAX Postback Problem

I am using Visual Studio 2005 with the AJAX extension.  I put a timer and a label control in an update panel.... The timer updates the labeltext to the current time once a second... I have a listbox outside the update panel and it is posting back once a second... (with the timer)... I have other controls on the same page thhat are NOT posting back...

the question is WHY is the control posting back... and how to STOP IT...

Please dont respond with javvascript options to put a timer on my page... the use of these controls is only a test of the AJAX functionality.

Thank you for your help...
0
NTGuru705
Asked:
NTGuru705
  • 3
  • 2
1 Solution
 
_TAD_Commented:
you put the timer in the updte panel as well?   That doesn't sound right.

Using AJAX
1) Add ScriptManager control to web page
2) Add UpdatePanel to Web Page
3) Add controls to UpdatePanel that you want to change for a given event (button click, timer tick, whatever).  The event firing control is usually not included - especially if they are timers.
4) Add control/timer which fires event to web page not to update panel (they can be part of the panel if they are manual event - like a button.  Automated event firing controls should not be included in the update panel.
5) Configure event firing control (set timer ticks, etc)
6) Add trigger/event from event firing control to the UpdatePanel Triggers collection
0
 
NTGuru705Author Commented:
Yes but take a look at this code for me.. the issue is that when the code below runs and the timer fires I always see the load event for lstqueues fire... this doesnt make any sense since the timer is inside a totally different updatepanel.

Thanks

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="doc.aspx.vb" Inherits="doc" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">

        </asp:ScriptManager>

        <asp:UpdatePanel runat="server" ID="udpTime" UpdateMode="conditional">

            <ContentTemplate>

                <asp:Timer ID="Timer1" runat="server" />

                <asp:Label runat="server" ID="lblTime" Text=" " Height="17px" />

            </ContentTemplate>

        </asp:UpdatePanel>

        <asp:UpdatePanel runat="server" ID="udpDocQueueList" UpdateMode="Conditional">

            <ContentTemplate>

                    Available Doc Queues:

                    <br />

                    <asp:DropDownList runat="server" ID="ddlQueues" /><br />

                    <br />

                   <asp:ListBox runat="server" ID="lstQueue" Height="100px" Width="300px"></asp:ListBox>

                    <asp:Button ID="btnGetDocs" runat="server" text="GO" Width="30px" />

            </ContentTemplate>

        </asp:UpdatePanel>

    </form>

</body>

</html>

 

 

Partial Class doc

    Inherits System.Web.UI.Page

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            'set up timer interval

            Timer1.Interval = 1000

            Timer1.Enabled = True

 

            'populate the drop down list

            ddlQueues.Items.Add("Default")

            ddlQueues.Items.Add("Test")

 

            'populate the list box

            lstQueue.Items.Add("Test1")

            lstQueue.Items.Add("Test2")

            lstQueue.Items.Add("Test3")

        End If

    End Sub

 

    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        lblTime.Text = Now.ToString

    End Sub

 

    Protected Sub lstQueue_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstQueue.Load

        'add a break point here to watch this event fire once a second,

        'even though the list box is not in the update panel with the timer.

    End Sub

End Class

 
0
 
_TAD_Commented:
Hmm.... well, according to your code, the list box is in an UpdatePanel although it is in a different panel from the label and timer.

Things to try/verify:

1) Look at your second update panel (the one the list box resides in) and verify that the UpdatePanel.Triggers collection is empty (or at least is not tied to the timer event or the other UpdatePanel).

2) take the timer out of the update panel and put it on the web page.  While I don't believe that this is causing a problem it is extra traffic and impacts performance (all 8 KB of it).  Ok, so maybe not a *huge* impact, but why add to the footprint?  87 KB * 3,000 concurrent users can start to add up.


As for testing, that wil have to wait a couple of days until after the Easter holiday.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
existenz2Commented:
<asp:UpdatePanel runat="server" ID="udpDocQueueList" UpdateMode="Conditional">

change that to:

<asp:UpdatePanel runat="server" ID="udpDocQueueList" UpdateMode="Conditional" ChildrenAsTriggers="False">

That might work (DropDownLists and UpdatePanel are evil though, I got some serious (performance) issues with those)
0
 
NTGuru705Author Commented:
Existenz we put a break on the load event for the listbox and we are still seeing that event fire...

I suppose I dont understand why the event would fire...

TAD - The triggers collection is empty....
0
 
NTGuru705Author Commented:
botttom line is the AJAX with MS is quite "buggy"... hopefully the next version will refine the deployment and correct some of the complication using AJAX in the visual studio enviroment.

I will give TAD the points for effort but we abandonded the AJAX for all but basic things in this project.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now