Why my ListBox Control in my Web Control is not Raising the SelectedIndexChanged Event ?

Discussion in 'ASP .Net' started by msnews.microsoft.com, Apr 28, 2005.

  1. Hi All,

    I am creating a control with ASP "ListBox" control.

    Also I have added necessary code to handle the ListBox.SelectedItemChanged
    Event.

    But surprisingly the control is not comng to this code at all.

    Why my ListBox Control in my Web Control is not Raising the
    SelectedIndexChanged Event ?

    Any suggestions please?

    Thanks
    Anand Ganesh
     
    msnews.microsoft.com, Apr 28, 2005
    #1
    1. Advertising

  2. msnews.microsoft.com

    Karl Seguin Guest

    did you set the AutoPostBack property to true?

    <asp:listbox ... AutoPostBack="True" />

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "msnews.microsoft.com" <> wrote in message
    news:%...
    > Hi All,
    >
    > I am creating a control with ASP "ListBox" control.
    >
    > Also I have added necessary code to handle the ListBox.SelectedItemChanged
    > Event.
    >
    > But surprisingly the control is not comng to this code at all.
    >
    > Why my ListBox Control in my Web Control is not Raising the
    > SelectedIndexChanged Event ?
    >
    > Any suggestions please?
    >
    > Thanks
    > Anand Ganesh
    >
    >
    >
     
    Karl Seguin, Apr 28, 2005
    #2
    1. Advertising

  3. Yes I did. Here is the code.

    protected override void CreateChildControls()

    {

    foreach(string st in this.GlobalArrayList)

    {

    TheListBox.Items.Add(st) ;

    }

    TheListBox.Attributes.Add("AutoPostBack","True") ;

    TheListBox.Attributes.Add("id","ListBoxCheck") ;

    TheListBox.Attributes.Add("runat","server") ;

    TheListBox.Attributes.Add("OnSelectedIndexChanged","TheListBox_SelectedIndexChanged")
    ;

    this.Controls.Add(TheListBox) ;

    Button TheButton = new Button() ;

    TheButton.Click +=new EventHandler(TheButton_Click);

    this.Controls.Add(TheButton) ;

    //base.CreateChildControls ();

    }


    But still the TheListBox_SelectedIndexChanged function is not being called.

    I am using the CreateChildControls() function to create my controls and I am
    not overiding and using the render function.

    Will this cause an issue?

    Thank
    Anand

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:ekyY$...
    > did you set the AutoPostBack property to true?
    >
    > <asp:listbox ... AutoPostBack="True" />
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    >
    >
    > "msnews.microsoft.com" <> wrote in message
    > news:%...
    >> Hi All,
    >>
    >> I am creating a control with ASP "ListBox" control.
    >>
    >> Also I have added necessary code to handle the
    >> ListBox.SelectedItemChanged Event.
    >>
    >> But surprisingly the control is not comng to this code at all.
    >>
    >> Why my ListBox Control in my Web Control is not Raising the
    >> SelectedIndexChanged Event ?
    >>
    >> Any suggestions please?
    >>
    >> Thanks
    >> Anand Ganesh
    >>
    >>
    >>

    >
    >
     
    msnews.microsoft.com, Apr 28, 2005
    #3
  4. Re: Why my ListBox Control in my Web Control is not Raising the Se

    TheListBox.Attributes.Add("AutoPostBack","true") ;
    Will add an "AutoPostBack" Attrubute to the rendered oupput of your control,
    but will not set this property of the control.

    try:

    TheListBox.AutoPostBack=true

    TheListBox.Attributes.Add("id","ListBoxCheck") ;
    TheListBox.OnSelectedIndexChanged +=new
    EventHandlerTheListBox_SelectedIndexChanged);


    Hope this helps.
    Brian
     
    =?Utf-8?B?YmNoYW5kbGV5?=, Apr 28, 2005
    #4
  5. On Wed, 27 Apr 2005 20:09:08 -0700 in
    microsoft.public.dotnet.framework.aspnet, "msnews.microsoft.com"
    <> wrote:

    >
    >TheListBox.Attributes.Add("AutoPostBack","True") ;
    >
    >TheListBox.Attributes.Add("id","ListBoxCheck") ;
    >
    >TheListBox.Attributes.Add("runat","server") ;
    >
    >TheListBox.Attributes.Add("OnSelectedIndexChanged","TheListBox_SelectedIndexChanged")
    >;
    >


    Hi,

    The 'attributes' collection you are adding to, is for client-side
    attributes only. Instead, use the appropriate property of the ListBox
    control like this:

    TheListBox.AutoPostBack = true;
    TheListBox.ID = "ListBoxCheck";
    TheListBox.SelectedIndexChanged += new
    EventHandler(TheListBox_SelectedIndexChanged);

    Roger
     
    Roger Helliwell, Apr 28, 2005
    #5
  6. Re: Why my ListBox Control in my Web Control is not Raising the Se

    Thanks a lot Brian it worked.


    "bchandley" <Bchan3@yahoo-.-com> wrote in message
    news:...
    > TheListBox.Attributes.Add("AutoPostBack","true") ;
    > Will add an "AutoPostBack" Attrubute to the rendered oupput of your
    > control,
    > but will not set this property of the control.
    >
    > try:
    >
    > TheListBox.AutoPostBack=true
    >
    > TheListBox.Attributes.Add("id","ListBoxCheck") ;
    > TheListBox.OnSelectedIndexChanged +=new
    > EventHandlerTheListBox_SelectedIndexChanged);
    >
    >
    > Hope this helps.
    > Brian
     
    msnews.microsoft.com, Apr 28, 2005
    #6
  7. Thanks a lot Roger it Worked.

    "Roger Helliwell" <> wrote in message
    news:...
    > On Wed, 27 Apr 2005 20:09:08 -0700 in
    > microsoft.public.dotnet.framework.aspnet, "msnews.microsoft.com"
    > <> wrote:
    >
    >>
    >>TheListBox.Attributes.Add("AutoPostBack","True") ;
    >>
    >>TheListBox.Attributes.Add("id","ListBoxCheck") ;
    >>
    >>TheListBox.Attributes.Add("runat","server") ;
    >>
    >>TheListBox.Attributes.Add("OnSelectedIndexChanged","TheListBox_SelectedIndexChanged")
    >>;
    >>

    >
    > Hi,
    >
    > The 'attributes' collection you are adding to, is for client-side
    > attributes only. Instead, use the appropriate property of the ListBox
    > control like this:
    >
    > TheListBox.AutoPostBack = true;
    > TheListBox.ID = "ListBoxCheck";
    > TheListBox.SelectedIndexChanged += new
    > EventHandler(TheListBox_SelectedIndexChanged);
    >
    > Roger
    >
     
    msnews.microsoft.com, Apr 28, 2005
    #7
    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. =?Utf-8?B?LU1U?=

    Raising SelectedIndexChanged event in a gridview

    =?Utf-8?B?LU1U?=, Jun 5, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    16,433
    =?Utf-8?B?SmF5?=
    Jun 6, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,266
    Smokey Grindel
    Dec 2, 2006
  3. Jay
    Replies:
    1
    Views:
    742
    PeterKellner
    Jun 8, 2006
  4. Scott Lemen

    Listbox Webcontrol SelectedIndexChanged Event not working

    Scott Lemen, Jun 28, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    567
  5. studen771
    Replies:
    0
    Views:
    550
    studen771
    Mar 28, 2007
Loading...

Share This Page