469,331 Members | 4,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

Checkboxlist Clientside rather than Serverside

I run some code on the changed event of checkbox lists. Its quite simple,
nothing more than showing / hiding some other parts of the page.
Using Autopostback and Server side code works fine, but is far too slow,
especially if the users are on modems.
I need to quite simply, add some java code to the onclick event of the input
tags of a checkboxlist.
However... Attributes.Add adds the onclick attribute and code to the
outlying table that the framework creates.
Is there a way of getting this code and events into the input tags?

Any help or ideas much appreciated.

Thanks
Robin
Nov 18 '05 #1
3 5291
Have you tried using individual checkbox controls with the attributes.add
rather than a checkboxlist control?
"Robin Day" <ro*******@advorto.com> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
I run some code on the changed event of checkbox lists. Its quite simple,
nothing more than showing / hiding some other parts of the page.
Using Autopostback and Server side code works fine, but is far too slow,
especially if the users are on modems.
I need to quite simply, add some java code to the onclick event of the input tags of a checkboxlist.
However... Attributes.Add adds the onclick attribute and code to the
outlying table that the framework creates.
Is there a way of getting this code and events into the input tags?

Any help or ideas much appreciated.

Thanks
Robin

Nov 18 '05 #2
The way the checkboxlist control works is very useful in this application.
It is deeply embedded into a number of custom webcontrols that are used in
various places on a number of systems.
I really don't want to have to produce my own version of the checkboxlist
when the only functional change I require is to add some onclick javascript.
Is it possible that there's some other way of accesseing the individual
input tags as the control renders? So I can manually add the events there?
Or possibly a way of using a custom validator that could fire the javascript
instead?

Thanks,
Robin

"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl...
Have you tried using individual checkbox controls with the attributes.add
rather than a checkboxlist control?
"Robin Day" <ro*******@advorto.com> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
I run some code on the changed event of checkbox lists. Its quite simple, nothing more than showing / hiding some other parts of the page.
Using Autopostback and Server side code works fine, but is far too slow,
especially if the users are on modems.
I need to quite simply, add some java code to the onclick event of the

input
tags of a checkboxlist.
However... Attributes.Add adds the onclick attribute and code to the
outlying table that the framework creates.
Is there a way of getting this code and events into the input tags?

Any help or ideas much appreciated.

Thanks
Robin


Nov 18 '05 #3
hi Robin,
I never expected to have to put all this time just to add that onclick
attribute to every checkbox in your checkboxlist control. Actually it does
sound very simple and then gets impossible --however I did get there
eventually.

At first I assumed trying to get to the items in the checkboxList item
collection and adding the onclick attribute would work, however no
attribute is being set --just turns up blank

For i = 0 To CheckBoxList1.Items.Count - 1
CheckBoxList1.Items.Item(i).Attributes.Item("oncli ck") =
"MyFunction();"
Next

whereas if you tried to set the text property of an item in the checkboxlist
it sets :S

Private Sub CheckBoxList1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CheckBoxList1.Load

For i = 0 To CheckBoxList1.Items.Count - 1
CheckBoxList1.Items.Item(i).text = "New value"
Next
End sub

When trying to add the onclick attribute through the controls collection of
the CheckboxList control the individual checkboxes get wrapped around span
tags with the onclick attribute i add. This is the same behaviour you get
when trying to add attributes to a checkbox control.

Unfortunately this is the behaviour of the checkbox control which you cannot
change and is useless to you because this will return a span element and not
the checkbox in itself if you tried to access the checkbox from javascript
via that onclick function you attach, however you can easily work around
this if you tried to pass "this.firstChild" element in javascript to your
function, which will return your checkbox element.

like this :

Dim c As Control
For Each c In CheckBoxList1.Controls

If TypeOf c Is CheckBox Then
CType(c, CheckBox).Attributes.Add("Onclick",
"functionClick(this.firstChild);")
End If
Next
Control output :

<table id="CheckBoxList1" border="0" style="Z-INDEX: 102; LEFT: 284px;
POSITION: absolute; TOP: 294px">
<tr>
<td><span Onclick="functionClick(this.firstChild)"><input
id="CheckBoxList1_0" type="checkbox"

name="CheckBoxList1:0" /><label for="CheckBoxList1_0">1</label></span></td>
</tr><tr>
<td><span Onclick="functionClick(this.firstChild)"><input
id="CheckBoxList1_1" type="checkbox"

name="CheckBoxList1:1" /><label for="CheckBoxList1_1">2</label></span></td>
</tr>
</table>

"Robin Day" <ro*******@advorto.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
The way the checkboxlist control works is very useful in this application.
It is deeply embedded into a number of custom webcontrols that are used in
various places on a number of systems.
I really don't want to have to produce my own version of the checkboxlist
when the only functional change I require is to add some onclick javascript. Is it possible that there's some other way of accesseing the individual
input tags as the control renders? So I can manually add the events there?
Or possibly a way of using a custom validator that could fire the javascript instead?

Thanks,
Robin

"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl...
Have you tried using individual checkbox controls with the attributes.add
rather than a checkboxlist control?
"Robin Day" <ro*******@advorto.com> wrote in message
news:OA**************@tk2msftngp13.phx.gbl...
I run some code on the changed event of checkbox lists. Its quite

simple, nothing more than showing / hiding some other parts of the page.
Using Autopostback and Server side code works fine, but is far too slow, especially if the users are on modems.
I need to quite simply, add some java code to the onclick event of the

input
tags of a checkboxlist.
However... Attributes.Add adds the onclick attribute and code to the
outlying table that the framework creates.
Is there a way of getting this code and events into the input tags?

Any help or ideas much appreciated.

Thanks
Robin



Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jack Black | last post: by
3 posts views Thread by Roy | last post: by
2 posts views Thread by Stimp | last post: by
2 posts views Thread by rishabhshrivastava | last post: by
7 posts views Thread by mc | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.