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

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

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
 
K

Karl Seguin

did you set the AutoPostBack property to true?

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

Karl
 
M

msnews.microsoft.com

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
 
G

Guest

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
 
R

Roger Helliwell

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
 
M

msnews.microsoft.com

Thanks a lot Roger it Worked.

Roger Helliwell said:
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
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top