Ajax Triggers for DropDownList don't fire

Discussion in 'ASP .Net Web Controls' started by Troy Donavan, Dec 22, 2006.

  1. Troy Donavan

    Troy Donavan Guest

    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>


    --
    Troy Donavan
    Troy Donavan, Dec 22, 2006
    #1
    1. Advertising

  2. Troy Donavan

    technoGirl Guest

    Troy,

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

    Troy Donavan wrote:
    > 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>
    >
    >
    > --
    > Troy Donavan
    technoGirl, Dec 24, 2006
    #2
    1. Advertising

  3. 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 (, 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.
    Walter Wang [MSFT], Dec 25, 2006
    #3
  4. Troy Donavan

    Troy Donavan Guest

    >AutoPostBack="true"

    What a wonderful concept!!! Thank you very much!

    --
    Troy Donavan


    "Walter Wang [MSFT]" wrote:

    > 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 (, 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.
    >
    >
    Troy Donavan, Dec 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bruce barker
    Replies:
    1
    Views:
    450
    =?Utf-8?B?U2lsZWVzaA==?=
    Apr 2, 2004
  2. =?Utf-8?B?RGFiYmxlcg==?=

    select dropdownlist triggers click on row

    =?Utf-8?B?RGFiYmxlcg==?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,154
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Apr 4, 2006
  3. =?Utf-8?B?QWxleA==?=

    Ajax - ascx and updatepanel triggers

    =?Utf-8?B?QWxleA==?=, Apr 26, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    795
    =?Utf-8?B?QWxleA==?=
    Apr 26, 2007
  4. Scott M.
    Replies:
    1
    Views:
    7,143
    Scott M.
    Mar 17, 2009
  5. Troy Donavan

    AJAX.NET triggers don't fire

    Troy Donavan, Dec 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    145
    Troy Donavan
    Dec 19, 2006
Loading...

Share This Page