Solved

ASP.net AJAX Postback Problem

Posted on 2007-04-06
6
809 Views
Last Modified: 2013-11-26
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
Comment
Question by:NTGuru705
  • 3
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 500 total points
ID: 18865382
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
 
LVL 1

Author Comment

by:NTGuru705
ID: 18866276
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
 
LVL 22

Expert Comment

by:_TAD_
ID: 18868298
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 14

Expert Comment

by:existenz2
ID: 18870586
<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
 
LVL 1

Author Comment

by:NTGuru705
ID: 18876944
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
 
LVL 1

Author Comment

by:NTGuru705
ID: 18966073
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now