Solved

ASP.net AJAX Postback Problem

Posted on 2007-04-06
6
798 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
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Expert Comment

by:existenz2
Comment Utility
<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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

12 Experts available now in Live!

Get 1:1 Help Now