Cheap Flights - Credit Card - Loans - Student Credit Cards - Loans

PDA

View Full Version : javascript and nested server controls


jimrthy
Dec 19th 2005, 10:30 pm
I have a couple of nested DataLists.
In the inner one, my ItemTemplate has a few controls (checkbox about whether to pay attention, a custom spinner for quantity, a database lookup for the individual price, etc)
I would like to be able to fiddle with things client-side. JavaScript--enable the spinner, calculate the total price, etc. Just a convenience thing, of course.
I can't figure out a way to give an ID/name to these controls. The basic idea is straightforward. <input id='whatever<% DoSomethingHere() %>'> Except that no longer works.
What am I missing?
TIA,
James

vectorgraphx
Dec 20th 2005, 7:00 am
James,

I'm trying to envision what you're asking - I've done similar things before but I'm a little unclear as to what it is that you're having trouble doing. are you wanting to dynamically name the controls, based on some other input? Are you trying to populate your javascript with server data dynamically? Are you trying to enable/disable parts of the form based on user input, i.e. checking a checkbox etc?

Let me know - if i knew a few more of your specifics i might be able to point you in the right direction :D

VG

riz
Dec 20th 2005, 7:26 am
I am envisioning that you are trying to manipulate server controls with JavaScript. There is really no reliable way to do it, unless you are will to take the control abstraction out and implement it yourself, dynamically preferably. The DataList control implements an html table. You can generate each cell and then add basic html controls, with id’s, to these cells. You can manipulate these controls with JavaScript at a latter time on client side. Like VG mentioned earlier, it is hard to speculate what you are trying to achieve without knowing the specific requirements.

vectorgraphx
Dec 20th 2005, 7:44 am
You know, a colleague of mine and i were having this very conversation the other day, the one about javascript and server controls. Up until the conversation i was having with him, i was also of the opinion that you couldn't interact with the server dynamically directly through javascript. He pointed me in a very interesting direction, which i've bookmarked for further reading. It's called AJAX, and it's apparently not new.

http://java.sun.com/developer/technicalArticles/J2EE/AJAX/index.html

check it out and see what you think - but it looks like true dynamic javascript scripting. I'm definitely going to research it some more, i'm very curious. Apparently this is the sort of thing that google maps uses, which does in fact seem to query the server dynamically without a page reload. Compare this to mapquest, which does the same thing as google maps, i.e. allowing you to zoom in and out and move around on the map, but does it via a page reload based on user input.

Curioser and curioser!

VG

jimrthy
Dec 20th 2005, 1:15 pm
I want the check box to en/disable a couple of other controls. Strictly client side.

I'm considering a custom control that uses the primary key for the row to build all three html id strings. That's a little more work than I want to put into it, though.

jimrthy
Dec 20th 2005, 1:17 pm
AJAX is sweet. Any web developer who hasn't started working with it needs to catch up quickly.

jimrthy
Dec 20th 2005, 1:32 pm
I knew I had to be missing something obvious.

Solution: use a plain html checkbox rather than <asp:checkbox>.

The reason I got stuck on it is probably that I just had a conversation yesterday with a friend who insisted there's pretty much never any reason to use the plain old html controls. I took his word on it, then spent hours beating my head against the wall over it.

Thanks everyone,
James

vectorgraphx
Dec 21st 2005, 6:02 am
funny how sometimes the simplest answer is the hardest to come up with... I too have a tendancy to overlook the obvious easy solutions when programming, hehe, I always think "well, it isn't working, it must be something complicated to fix it" :D


Glad you got it to work man!

Later

VG