Monday, March 26, 2012

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

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 Ganeshdid 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" <aganesh@.nobel-systems.com> wrote in message
news:%23i0MFQ5SFHA.1040@.TK2MSFTNGP10.phx.gbl...
> 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
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$z5SFHA.3636@.TK2MSFTNGP14.phx.gbl...
> 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" <aganesh@.nobel-systems.com> wrote in message
> news:%23i0MFQ5SFHA.1040@.TK2MSFTNGP10.phx.gbl...
>> 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
>>
>>
>>
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
On Wed, 27 Apr 2005 20:09:08 -0700 in
microsoft.public.dotnet.framework.aspnet, "msnews.microsoft.com"
<aganesh@.nobel-systems.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
Thanks a lot Roger it Worked.

"Roger Helliwell" <rhelliwell@.telus.net> wrote in message
news:ea017193prs851irdkc47c22ipfvvbrdbh@.4ax.com...
> On Wed, 27 Apr 2005 20:09:08 -0700 in
> microsoft.public.dotnet.framework.aspnet, "msnews.microsoft.com"
> <aganesh@.nobel-systems.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
Thanks a lot Brian it worked.

"bchandley" <Bchan3@.yahoo-.-com> wrote in message
news:601A2E63-1113-4C3D-8E5E-9779755A4F27@.microsoft.com...
> 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

0 comments:

Post a Comment