Ajax Triggers for DropDownList don't fire

T

Troy Donavan

I'm trying to get a partial page (Ajax style) update when the selection of a
DropDownList changes. I'm not having much luck. I will continue plugging
away at the sample applications in hopes of finding some hints, but
meanwhile, if someone could point out to me what I am doing wrong, I would
appreciate it. Here is a page with three controls on it. They are for
selection of Country, State and Locality. The idea is that when one chooses
the country, the possible selections for state (region) would then update and
similarly for localities.

Let me know if you can spot my problem. Here is the code:


<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.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" />
<div>

<asp:UpdatePanel ID="UPCountry" runat="server">
<ContentTemplate>

<asp:DropDownList ID="DDCountry" runat="server"
style="z-index: 100; left: 500px; position: absolute; top: 100px; width:
200px" OnLoad="DDCountry_Load">
</asp:DropDownList>

<asp:DropDownList style="Z-INDEX: 100; LEFT: 500px; WIDTH:
200px; POSITION: absolute; TOP: 130px" id="DDState" runat="server"
OnLoad="DDState_Load">
</asp:DropDownList>

<asp:DropDownList style="Z-INDEX: 100; LEFT: 500px; WIDTH:
200px; POSITION: absolute; TOP: 160px" id="DDLocality" runat="server"
OnLoad="DDLocality_Load">
</asp:DropDownList>
</ContentTemplate>
<triggers>
<asp:AsyncPostBackTrigger ControlID="DDState"
EventName="TextChanged"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="DDCountry"
EventName="TextChanged"></asp:AsyncPostBackTrigger>
</triggers>
</asp:UpdatePanel>

</div>
</form>
</body>
</html>
 
T

technoGirl

Troy,

Shouldn't you be using OnSelectedIndexChanged =
DDCountry_SelectedIndexChanged for your drop downs??? Since you want a
ajax style functionality??
Tina
 
W

Walter Wang [MSFT]

Hi Troy,

As Tina pointed out, if you want to update second DropDownList when the
first one changes, you need to handle the first one's SelectedIndexChanged
event instead of the Load event. Also you need to set the first
DropDownList's AutoPostBack to true:

<asp:UpdatePanel ID="UPCountry" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DDCountry" runat="server"
Style="z-index: 100; left: 500px;
position: absolute; top: 100px; width: 200px"
OnLoad="DDCountry_Load"
OnSelectedIndexChanged="DDCountry_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>



Protected Sub DDCountry_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
DDState.Items.Clear()
Dim s As String = DDCountry.SelectedItem.Text
For i As Integer = 1 To 2
DDState.Items.Add(s + "_" + i.ToString())
Next
End Sub



Hope this helps.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top