1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

javascript and nested server controls

Discussion in 'C#' started by jimrthy, Dec 19, 2005.

  1. #1
    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
     
    jimrthy, Dec 19, 2005 IP
  2. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    vectorgraphx, Dec 20, 2005 IP
  3. riz

    riz Peon

    Messages:
    82
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    riz, Dec 20, 2005 IP
  4. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    vectorgraphx, Dec 20, 2005 IP
  5. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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 20, 2005 IP
  6. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    AJAX is sweet. Any web developer who hasn't started working with it needs to catch up quickly.
     
    jimrthy, Dec 20, 2005 IP
  7. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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
     
    jimrthy, Dec 20, 2005 IP
  8. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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
     
    vectorgraphx, Dec 21, 2005 IP