English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am coding a web page that uses ASP controls "asp:radiobuttonlist" and "asp:checkbox". I want to code event handlers that enable and disable other controls based on what these controls are doing. Here's the problem: I don't want to do an auto postback because the page refreshes and the scroll bar goes back to the top of the page. I would rather these behave like traditional HTML controls with Javascript event handlers, but I don't want to do that because I am populating the controls out of a database.

Is it even possible to do this? Am I just screwed? Is there a way to make Javascript pick up events from these controls and then enable/disable without reloading the page?

2006-07-05 04:26:57 · 3 answers · asked by sideshot72 3 in Computers & Internet Programming & Design

3 answers

With the ASP:Checkbox, you can just add a JavaScript OnClick() event to the tag:



That will call the MyFunction() function that you've created.

With the RadioButtonList it's a bit harder. You would want to override the OnRender event for the control and manually build it, adding in your event call.

And for the record, there are a few ways of retaining the scroll position of a window after postback.

2006-07-05 05:36:29 · answer #1 · answered by Kryzchek 4 · 0 0

for chekcbox, use this line of code
mycheckbox.attributes.add("onclick","MyJSFunctionName()")

for radio button list, u have to do some work.. After u populate the list by calling list.databind() method, iterate through every item and add js in similar fashoim

rbl.datasource=dt
rbl.databind()

for i as integer=0 to rbl.items.count-1
rbl.items(i).attribute.add("onclick","MyJSFunctionName()")
next

here , MyJSFunctionName() is the javascript function , which will enable/disable other controls depending upon ur logic.

Put this function in element of page.

2006-07-05 06:07:35 · answer #2 · answered by Shahzad Ahmed 2 · 0 0

You may want to check out the latest Atlas release (.Net Ajax layer). It allows for many of these server side behaviors w/o visible page refreshes.

2006-07-05 15:08:37 · answer #3 · answered by MC Nat 2 · 0 0

fedest.com, questions and answers