Problem with UpdatePanel

I have just started using AJAX and have a Dropdown inside an AJAX UpdatePanel (see attach code).  I thought the concept of the UpdatePanel was it would control the postback for its enclosed components without causing a postback of the entire page.

But, when I make a selectin in the Dropdown, the entire page "flashes" as it is refreshed.  What am I doing wrong?
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" />
  </Triggers>
  <ContentTemplate>
    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="sqlds_contractor"
      DataTextField="Company_Name" DataValueField="ID" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
      AutoPostBack="true">
    </asp:DropDownList>
  </ContentTemplate>
</asp:UpdatePanel>

Open in new window

LVL 1
wsturdevAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
wsturdevConnect With a Mentor Author Commented:
I solved it by removing this:
<xhtmlConformance mode="Legacy"/>
from my WebConfig
0
 
zadeveloperCommented:
you need to specifiy the events within the update panel.
If you are just satrting out I would suggest visiting:
http://www.codeplex.com/Ajax
 
0
 
zadeveloperCommented:
there is a very good section there: Tutorials, Reference Documentation, and Sample Applications
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
zadeveloperCommented:
for your immediate problem try:
<asp:ScriptManager ID="scriptMgr" runat="server" />


<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
  <Triggers> 
    <asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" /> 
  </Triggers> 
  <ContentTemplate> 
    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="sqlds_contractor" 
      DataTextField="Company_Name" DataValueField="ID" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" 
      AutoPostBack="true"> 
    </asp:DropDownList> 
  </ContentTemplate> 
</asp:UpdatePanel>

Open in new window

0
 
HainKurtSr. System AnalystCommented:
what is happening if you do

AutoPostBack="false"

@ line 8
0
 
zadeveloperCommented:
then the event  DropDownList2_SelectedIndexChanged will never fire.
0
 
wsturdevAuthor Commented:
Sorry -- forgot to include <asp:ScriptManager ID="scriptMgr" runat="server" /> in my sample code.  I already have that.
0
 
zadeveloperCommented:
Can u place the HTML for the entire body please
0
 
HainKurtSr. System AnalystCommented:
I have this and working fine
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="lbUsers" />
            </Triggers>
            <ContentTemplate>
                You live in :
                <asp:Literal ID="ltrSelCity" runat="server" /><br />
                <asp:ListBox ID="lbUsers" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="4">Ankara</asp:ListItem>
                    <asp:ListItem Value="34">Istanbul</asp:ListItem>
                    <asp:ListItem Value="27">Gaziantep</asp:ListItem>
                </asp:ListBox><br />
                Post back time :
                <asp:Literal ID="ltrPBTime" runat="server" /><br />
            </ContentTemplate>
        </asp:UpdatePanel>

-------- and code behind ----------

    Protected Sub UpdatePanel1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdatePanel1.Load
        Dim a As String = ""
        ltrPBTime.Text = Now.ToString
    End Sub

    Protected Sub lbUsers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbUsers.SelectedIndexChanged
        ltrSelCity.Text = lbUsers.SelectedItem.Text
    End Sub

Open in new window

0
 
HainKurtSr. System AnalystCommented:
remove this

EventName="SelectedIndexChanged"

I created a mix of form, button and update panel, working fine... have a look at this:
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="lbUsers" />
            </Triggers>
            <ContentTemplate>
                You live in :
                <asp:Literal ID="ltrSelCity" runat="server" /><br />
                <asp:ListBox ID="lbUsers" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="4">Ankara</asp:ListItem>
                    <asp:ListItem Value="34">Istanbul</asp:ListItem>
                    <asp:ListItem Value="27">Gaziantep</asp:ListItem>
                </asp:ListBox>
                <br />
                Ajax UP post back time :
                <asp:Literal ID="ltrPBTime" runat="server" /><br />
            </ContentTemplate>
        </asp:UpdatePanel>
        Page post back time :
        <asp:Literal ID="ltrFPBTime" runat="server" /><br />
        <asp:Button Text="Post" runat="server" ID="btnPB" />
    </div>
    </form>

-------- and code ---------
Partial Class ajax
    Inherits System.Web.UI.Page

    Protected Sub UpdatePanel1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdatePanel1.Load
        Dim a As String = ""
        ltrPBTime.Text = Now.ToString
    End Sub

    Protected Sub lbUsers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbUsers.SelectedIndexChanged
        ltrSelCity.Text = lbUsers.SelectedItem.Text
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            ltrFPBTime.Text = Now.ToString
        End If
    End Sub
End Class

Open in new window

0
 
wsturdevAuthor Commented:
I removed this     EventName="SelectedIndexChanged"
I also removed this   OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
Same problem.
Is it possibly because of this?
DataSourceID="sqlds_contractor"
Does the fact I am referencing a data source cause the postback?
0
 
wsturdevAuthor Commented:
I have meetings the rest of the day -- will check back tonight (if possible) or tomorrow morning.
0
 
wsturdevAuthor Commented:
One point I need to mention is the AJAX UpdatePanel is inside an ASP.NET Panel which is inside a .ascx.
I di dnot think that would matter, but a colleague suggests it might be relevant.
0
 
MogalManicCommented:
What version of mdac are you using?
http://support.microsoft.com/kb/301202
0
 
amar31282Commented:
use this inside the update panel

ChildrenAsTriggers="true"
0
 
amar31282Commented:
use this inside the update panel

ChildrenAsTriggers="true"
0
 
MogalManicCommented:
ignore my comment.  It got posted to the wong thread.
0
 
codingbeaverCommented:
Since your DropDownList control is already in the UpdatePanel, you don't need <Triggers> section. Remove this from your code:
 <Triggers>
    <asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" />
  </Triggers>
0
 
codingbeaverCommented:
Also, I guess based on the selction of the DropDownList, you will update some section of the page, what is it? Is it in the UpdatePanel? If not, you will need to put the section in the UpdatePanel to avoid the "flicker" of the screen.
0
 
wsturdevAuthor Commented:
Thanks for the responses.  I was unavailable yesterday and will be for most of today, so I will try your suggestions this weekend.
0
 
wsturdevAuthor Commented:
Sorry for the delay -- been sick.
I have tried what you have suggested, but still have the problem.
One thing to note, however...  In my original example, I have a DropdownList with an external data source.  In your examples, you have a ListBox with values supplied in line.  Can you set up an example more like mine?
Also, in my "DropDownList2_SelectedIndexChanged", I do not have any code yet.  All I am doing at the moment is to select a value from the dropdown list, and the "flash" occurs.
 
0
 
codingbeaverCommented:
What section of the page are you trying to update that causes the "flash"?
0
 
amar31282Commented:
can u please paste the full aspx page code...
0
All Courses

From novice to tech pro — start learning today.