Onselectedindexchanged event not fired

Last post 10-17-2008 4:22 AM by Hua-Jun Li - MSFT. 4 replies.

Sort Posts:

  • Onselectedindexchanged event not fired

    10-10-2008, 8:44 AM
    • Member
      1 point Member
    • zeetech
    • Member since 10-10-2008, 12:34 PM
    • Posts 18

     I have add a dropdownlist in a usercontrol and i register that usercontrol into a webform

    I have set postback property as True and i add a method in  on selected index changed Event.

    But it was not fired, then i have searched in forums, they said to set enable view state property as true, i have tried that too.

    But still it's not working

     

  • Re: Onselectedindexchanged event not fired

    10-10-2008, 9:19 AM
    • All-Star
      122,905 point All-Star
    • XIII
    • Member since 06-30-2002, 11:59 PM
    • Essen, Belgium
    • Posts 13,604
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Hi,

    and welcome to the ASP.NET forums.

    Can you post the relevant parts of your markup and codebehind? Also did you try to place breakpoints in the eventhandler? Is this dropdownlist added dynamically?

    Grz, Kris.

  • Re: Onselectedindexchanged event not fired

    10-14-2008, 4:03 AM
    Answer

    Hi zeetech,

    Please set the following property to be true.

    EnableViewState, autoPostBack,AutoEventWireup.

    Also you can remove the extra header directive from header.

    If you create the dropdownlist dynamicly, you should assign the id for it.

    Here is the article, you can read it.

    http://forums.microsoft.com/msdn/ShowPost.aspx?PageIndex=1&SiteID=1&PageID=1&PostID=3357365

    http://www.codenewsgroups.net/group/microsoft.public.dotnet.framework.aspnet.webcontrols/topic1279.aspx  

    Sincerely,
    Hua Jun Li
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Onselectedindexchanged event not fired

    10-16-2008, 5:12 AM
    • Member
      1 point Member
    • zeetech
    • Member since 10-10-2008, 12:34 PM
    • Posts 18
    please  help me to do this

     this is the code i have used in VS2005,


    <%@ Page Language="C#" AutoEventWireup="true" Codebehind="DropDownlistWF.aspx.cs"
        Inherits="TestProject.DropDownlistWF" EnableViewState="true"%>

    <!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">
            <div>
                <asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
                    <asp:ListItem Text="Item1" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Item2" Value="2"></asp:ListItem>
                    <asp:ListItem Text="Item3" Value="3"></asp:ListItem>
                </asp:DropDownList>
            </div>
        </form>
    </body>
    </html>

     

    ----------code behind -------------------

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace TestProject
    {
        public partial class DropDownlistWF : System.Web.UI.Page
        {
         
            protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
            {
                Response.Write(ddl.SelectedItem.Text);
            }
        }
    }
  • Re: Onselectedindexchanged event not fired

    10-17-2008, 4:22 AM

    Hi zeetech,

    Maybe your can remove namespace 'TestProject'.

    The following code run well.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDownlistWF.aspx.cs" Inherits="DropDownlistWF" %>

    <!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">
            <div>
                <asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
                    <asp:ListItem Text="Item1" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Item2" Value="2"></asp:ListItem>
                    <asp:ListItem Text="Item3" Value="3"></asp:ListItem>
                </asp:DropDownList>
            </div>
        </form>
    </body>
    </html>
    ----------code behind -------------------

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class DropDownlistWF : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Write(ddl.SelectedItem.Text);
        }
    }
     

    Sincerely,
    Hua Jun Li
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (5 items)