Question:
ASP.NET / Javascript Problem (Please see details)?
sideshot72
2006-07-05 08:26:57 UTC
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?
Three answers:
Kryzchek
2006-07-05 09:36:29 UTC
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.
Shahzad Ahmed
2006-07-05 10:07:35 UTC
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.
MC Nat
2006-07-05 19:08:37 UTC
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.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...