Home All Groups Group Topic Archive Search About

CheckBoxList problem. Want to add some javascript to each checkbox

Author
15 Dec 2005 7:27 PM
ThunderMusic
Hi,
I have a CheckBoxList and I want to add some javascript code to each
CheckBox created by this CheckBoxList. I tried iterating through all items
of the list, all the controls, do a FindControl, et al. with no good result.
I would use the Control.Attribute.Add("OnClick", "some javascript code")

Does someone know a solution?

Thanks

ThunderMusic

Author
15 Dec 2005 9:38 PM
Rob Schieber
ThunderMusic wrote:
> Hi,
> I have a CheckBoxList and I want to add some javascript code to each
> CheckBox created by this CheckBoxList. I tried iterating through all items
> of the list, all the controls, do a FindControl, et al. with no good result.
> I would use the Control.Attribute.Add("OnClick", "some javascript code")
>
> Does someone know a solution?
>
> Thanks
>
> ThunderMusic
>
>

If you want to add javascript in this way you'll need to do it before
the controls are rendered  to the page i.e. before page load.  Try to
using Control.Attribs.Add in the soonest possible event; usually
onInitEvent or onItemDataBound.

--
Rob Schieber
Are all your drivers up to date? click for free checkup

Author
16 Dec 2005 1:36 PM
ThunderMusic
Thanks for the help. Indeed, it worked in the OnInit method of the page, but
I changed the way I'm doing it, so now the OnClick event is managed directly
from the form, so everything clickable is readonly (it is a print preview
form) so I only have to manage the OnClick once.

Thanks a lot

ThunderMusic

Show quoteHide quote
"Rob Schieber" <schie***@hotmail.com> wrote in message
news:egH6s$bAGHA.2036@TK2MSFTNGP14.phx.gbl...
> ThunderMusic wrote:
>> Hi,
>> I have a CheckBoxList and I want to add some javascript code to each
>> CheckBox created by this CheckBoxList. I tried iterating through all
>> items of the list, all the controls, do a FindControl, et al. with no
>> good result. I would use the Control.Attribute.Add("OnClick", "some
>> javascript code")
>>
>> Does someone know a solution?
>>
>> Thanks
>>
>> ThunderMusic
>
> If you want to add javascript in this way you'll need to do it before the
> controls are rendered  to the page i.e. before page load.  Try to using
> Control.Attribs.Add in the soonest possible event; usually onInitEvent or
> onItemDataBound.
>
> --
> Rob Schieber
Author
20 Dec 2005 4:37 AM
clintonG
The CheckBoxList is giving me a hard time too if I may jump into this news
article. The checkboxes have colored backgrounds I can't figure out how to
get rid of and I can't apply padding or margins to the text noting this is a
piece of cake when working with HTML but this control seems to be a
composite control and I can't figure out how to access the properties I
need. Any idea how I might clean it up?

<%= Clinton Gallagher

Show quoteHide quote
"ThunderMusic" <NOSPAM@NoSPAM.Info> wrote in message
news:uHCaHXkAGHA.2320@TK2MSFTNGP11.phx.gbl...
> Thanks for the help. Indeed, it worked in the OnInit method of the page,
> but I changed the way I'm doing it, so now the OnClick event is managed
> directly from the form, so everything clickable is readonly (it is a print
> preview form) so I only have to manage the OnClick once.
>
> Thanks a lot
>
> ThunderMusic
>
> "Rob Schieber" <schie***@hotmail.com> wrote in message
> news:egH6s$bAGHA.2036@TK2MSFTNGP14.phx.gbl...
>> ThunderMusic wrote:
>>> Hi,
>>> I have a CheckBoxList and I want to add some javascript code to each
>>> CheckBox created by this CheckBoxList. I tried iterating through all
>>> items of the list, all the controls, do a FindControl, et al. with no
>>> good result. I would use the Control.Attribute.Add("OnClick", "some
>>> javascript code")
>>>
>>> Does someone know a solution?
>>>
>>> Thanks
>>>
>>> ThunderMusic
>>
>> If you want to add javascript in this way you'll need to do it before the
>> controls are rendered  to the page i.e. before page load.  Try to using
>> Control.Attribs.Add in the soonest possible event; usually onInitEvent or
>> onItemDataBound.
>>
>> --
>> Rob Schieber
>
>
Author
20 Dec 2005 4:50 AM
ThunderMusic
my guess would be to add your things in the OnInit event of the page...  it
worked for me, maybe it will for you too...

"clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> a écrit dans le
message de news: %23EcWK8RBGHA.***@TK2MSFTNGP11.phx.gbl...
Show quoteHide quote
> The CheckBoxList is giving me a hard time too if I may jump into this news
> article. The checkboxes have colored backgrounds I can't figure out how to
> get rid of and I can't apply padding or margins to the text noting this is
> a piece of cake when working with HTML but this control seems to be a
> composite control and I can't figure out how to access the properties I
> need. Any idea how I might clean it up?
>
> <%= Clinton Gallagher
>
> "ThunderMusic" <NOSPAM@NoSPAM.Info> wrote in message
> news:uHCaHXkAGHA.2320@TK2MSFTNGP11.phx.gbl...
>> Thanks for the help. Indeed, it worked in the OnInit method of the page,
>> but I changed the way I'm doing it, so now the OnClick event is managed
>> directly from the form, so everything clickable is readonly (it is a
>> print preview form) so I only have to manage the OnClick once.
>>
>> Thanks a lot
>>
>> ThunderMusic
>>
>> "Rob Schieber" <schie***@hotmail.com> wrote in message
>> news:egH6s$bAGHA.2036@TK2MSFTNGP14.phx.gbl...
>>> ThunderMusic wrote:
>>>> Hi,
>>>> I have a CheckBoxList and I want to add some javascript code to each
>>>> CheckBox created by this CheckBoxList. I tried iterating through all
>>>> items of the list, all the controls, do a FindControl, et al. with no
>>>> good result. I would use the Control.Attribute.Add("OnClick", "some
>>>> javascript code")
>>>>
>>>> Does someone know a solution?
>>>>
>>>> Thanks
>>>>
>>>> ThunderMusic
>>>
>>> If you want to add javascript in this way you'll need to do it before
>>> the controls are rendered  to the page i.e. before page load.  Try to
>>> using Control.Attribs.Add in the soonest possible event; usually
>>> onInitEvent or onItemDataBound.
>>>
>>> --
>>> Rob Schieber
>>
>>
>
>
Author
21 Dec 2005 8:44 PM
clintonG
Hmmm. I was concerned that I would have to write code to work around a poor
implementation of these "list" controls.

<%= Clinton Gallagher



Show quoteHide quote
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> wrote in message
news:eQsArDSBGHA.740@TK2MSFTNGP12.phx.gbl...
> my guess would be to add your things in the OnInit event of the page...
> it worked for me, maybe it will for you too...
>
> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> a écrit dans le
> message de news: %23EcWK8RBGHA.***@TK2MSFTNGP11.phx.gbl...
>> The CheckBoxList is giving me a hard time too if I may jump into this
>> news article. The checkboxes have colored backgrounds I can't figure out
>> how to get rid of and I can't apply padding or margins to the text noting
>> this is a piece of cake when working with HTML but this control seems to
>> be a composite control and I can't figure out how to access the
>> properties I need. Any idea how I might clean it up?
>>
>> <%= Clinton Gallagher
>>
>> "ThunderMusic" <NOSPAM@NoSPAM.Info> wrote in message
>> news:uHCaHXkAGHA.2320@TK2MSFTNGP11.phx.gbl...
>>> Thanks for the help. Indeed, it worked in the OnInit method of the page,
>>> but I changed the way I'm doing it, so now the OnClick event is managed
>>> directly from the form, so everything clickable is readonly (it is a
>>> print preview form) so I only have to manage the OnClick once.
>>>
>>> Thanks a lot
>>>
>>> ThunderMusic
>>>
>>> "Rob Schieber" <schie***@hotmail.com> wrote in message
>>> news:egH6s$bAGHA.2036@TK2MSFTNGP14.phx.gbl...
>>>> ThunderMusic wrote:
>>>>> Hi,
>>>>> I have a CheckBoxList and I want to add some javascript code to each
>>>>> CheckBox created by this CheckBoxList. I tried iterating through all
>>>>> items of the list, all the controls, do a FindControl, et al. with no
>>>>> good result. I would use the Control.Attribute.Add("OnClick", "some
>>>>> javascript code")
>>>>>
>>>>> Does someone know a solution?
>>>>>
>>>>> Thanks
>>>>>
>>>>> ThunderMusic
>>>>
>>>> If you want to add javascript in this way you'll need to do it before
>>>> the controls are rendered  to the page i.e. before page load.  Try to
>>>> using Control.Attribs.Add in the soonest possible event; usually
>>>> onInitEvent or onItemDataBound.
>>>>
>>>> --
>>>> Rob Schieber
>>>
>>>
>>
>>
>
>
Author
22 Dec 2005 4:14 AM
ThunderMusic
hi,
yes, but we're talking about 1line of code

YourChkBoxList.Attributes.Add("Style", "Margin: 5px; background-color:
#FFFFFF")

and that's about it. if it's not exactly it, it is quite similar...  As I
said in an earlier post, I don't use it anymore because I found an easier
solution to my problem, but I think it's the way I was doing it. if it's not
working, try going trought all the controls (child controls of your
chkboxlist) and add the attribute, but in the OnInit, I don't think they
will be created, so that's why you can add it directly to the chkboxlist...
and as for style, you could try to add it directly in the aspx code because
it's not likely to change... I didn't try it, but it could work...  it was
not suited for my problem though as each chkbox had something
different......

I hope it helps

ThunderMusic


"clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> a écrit dans le
message de news: eLldM9mBGHA.3***@tk2msftngp13.phx.gbl...
Show quoteHide quote
> Hmmm. I was concerned that I would have to write code to work around a
> poor implementation of these "list" controls.
>
> <%= Clinton Gallagher
>
>
>
> "ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> wrote in message
> news:eQsArDSBGHA.740@TK2MSFTNGP12.phx.gbl...
>> my guess would be to add your things in the OnInit event of the page...
>> it worked for me, maybe it will for you too...
>>
>> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> a écrit dans le
>> message de news: %23EcWK8RBGHA.***@TK2MSFTNGP11.phx.gbl...
>>> The CheckBoxList is giving me a hard time too if I may jump into this
>>> news article. The checkboxes have colored backgrounds I can't figure out
>>> how to get rid of and I can't apply padding or margins to the text
>>> noting this is a piece of cake when working with HTML but this control
>>> seems to be a composite control and I can't figure out how to access the
>>> properties I need. Any idea how I might clean it up?
>>>
>>> <%= Clinton Gallagher
>>>
>>> "ThunderMusic" <NOSPAM@NoSPAM.Info> wrote in message
>>> news:uHCaHXkAGHA.2320@TK2MSFTNGP11.phx.gbl...
>>>> Thanks for the help. Indeed, it worked in the OnInit method of the
>>>> page, but I changed the way I'm doing it, so now the OnClick event is
>>>> managed directly from the form, so everything clickable is readonly (it
>>>> is a print preview form) so I only have to manage the OnClick once.
>>>>
>>>> Thanks a lot
>>>>
>>>> ThunderMusic
>>>>
>>>> "Rob Schieber" <schie***@hotmail.com> wrote in message
>>>> news:egH6s$bAGHA.2036@TK2MSFTNGP14.phx.gbl...
>>>>> ThunderMusic wrote:
>>>>>> Hi,
>>>>>> I have a CheckBoxList and I want to add some javascript code to each
>>>>>> CheckBox created by this CheckBoxList. I tried iterating through all
>>>>>> items of the list, all the controls, do a FindControl, et al. with no
>>>>>> good result. I would use the Control.Attribute.Add("OnClick", "some
>>>>>> javascript code")
>>>>>>
>>>>>> Does someone know a solution?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> ThunderMusic
>>>>>
>>>>> If you want to add javascript in this way you'll need to do it before
>>>>> the controls are rendered  to the page i.e. before page load.  Try to
>>>>> using Control.Attribs.Add in the soonest possible event; usually
>>>>> onInitEvent or onItemDataBound.
>>>>>
>>>>> --
>>>>> Rob Schieber
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
23 Dec 2005 5:35 PM
clintonG
Thanks for your comments. Accessing the child controls (Labels) of the
CheckBoxList is going to be a bit tricky I think as the Labels emitted by a
ListItem are already being rendered using a <span>. I am also using the
CheckBoxList as a child of a Wizard in 2.0 Master Pages which adds a bit of
spaghetti to the bowl. I better just get busy...

<%= Clinton Gallagher

Show quoteHide quote
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> wrote in message
news:%23C2r24qBGHA.2320@TK2MSFTNGP11.phx.gbl...
> hi,
> yes, but we're talking about 1line of code
>
> YourChkBoxList.Attributes.Add("Style", "Margin: 5px; background-color:
> #FFFFFF")
>
> and that's about it. if it's not exactly it, it is quite similar...  As I
> said in an earlier post, I don't use it anymore because I found an easier
> solution to my problem, but I think it's the way I was doing it. if it's
> not working, try going trought all the controls (child controls of your
> chkboxlist) and add the attribute, but in the OnInit, I don't think they
> will be created, so that's why you can add it directly to the
> chkboxlist... and as for style, you could try to add it directly in the
> aspx code because it's not likely to change... I didn't try it, but it
> could work...  it was not suited for my problem though as each chkbox had
> something different......
>
> I hope it helps
>
> ThunderMusic
>
>
> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> a écrit dans le
> message de news: eLldM9mBGHA.3***@tk2msftngp13.phx.gbl...
>> Hmmm. I was concerned that I would have to write code to work around a
>> poor implementation of these "list" controls.
>>
>> <%= Clinton Gallagher
>>
>>
>>
>> "ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> wrote in message
>> news:eQsArDSBGHA.740@TK2MSFTNGP12.phx.gbl...
>>> my guess would be to add your things in the OnInit event of the page...
>>> it worked for me, maybe it will for you too...
>>>
>>> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> a écrit dans
>>> le message de news: %23EcWK8RBGHA.***@TK2MSFTNGP11.phx.gbl...
>>>> The CheckBoxList is giving me a hard time too if I may jump into this
>>>> news article. The checkboxes have colored backgrounds I can't figure
>>>> out how to get rid of and I can't apply padding or margins to the text
>>>> noting this is a piece of cake when working with HTML but this control
>>>> seems to be a composite control and I can't figure out how to access
>>>> the properties I need. Any idea how I might clean it up?
>>>>
>>>> <%= Clinton Gallagher
>>>>
>>>> "ThunderMusic" <NOSPAM@NoSPAM.Info> wrote in message
>>>> news:uHCaHXkAGHA.2320@TK2MSFTNGP11.phx.gbl...
>>>>> Thanks for the help. Indeed, it worked in the OnInit method of the
>>>>> page, but I changed the way I'm doing it, so now the OnClick event is
>>>>> managed directly from the form, so everything clickable is readonly
>>>>> (it is a print preview form) so I only have to manage the OnClick
>>>>> once.
>>>>>
>>>>> Thanks a lot
>>>>>
>>>>> ThunderMusic
>>>>>
>>>>> "Rob Schieber" <schie***@hotmail.com> wrote in message
>>>>> news:egH6s$bAGHA.2036@TK2MSFTNGP14.phx.gbl...
>>>>>> ThunderMusic wrote:
>>>>>>> Hi,
>>>>>>> I have a CheckBoxList and I want to add some javascript code to each
>>>>>>> CheckBox created by this CheckBoxList. I tried iterating through all
>>>>>>> items of the list, all the controls, do a FindControl, et al. with
>>>>>>> no good result. I would use the Control.Attribute.Add("OnClick",
>>>>>>> "some javascript code")
>>>>>>>
>>>>>>> Does someone know a solution?
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> ThunderMusic
>>>>>>
>>>>>> If you want to add javascript in this way you'll need to do it before
>>>>>> the controls are rendered  to the page i.e. before page load.  Try to
>>>>>> using Control.Attribs.Add in the soonest possible event; usually
>>>>>> onInitEvent or onItemDataBound.
>>>>>>
>>>>>> --
>>>>>> Rob Schieber
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

Bookmark and Share