views:

204

answers:

1

I have some user controls that I want to add some client side functionality to.

Let say 1 control has a hidden field and a bunch of checkboxes. When a checkbox is checked, it sets the hidden field to 'YES'. How could I $get that control in the hosting control or page, and call some function on it that would return the value of that hidden field?

If I have a couple of these on the page, I'd like to be able to do this:

var choices1 = $get('choices1_id')
if(choices1.dirty() = 'YES')
    //do whatever
var choices2 = $get('choices2_is')
if(choices2.dirty() = 'YES')
    //do whatever

I might be looking for something like this: http://jimblackler.net/blog/?p=23 but I'm not sure how to access the object(s) from the parent.

thanks, Mark

A: 

I take it the problem you are running into is that ASP.Net can mangle the id of the control?

In that case What I normally do is either note how the id is mangled for simple pages, and write the javascript accordingly, or for more complex scenarios I'll check the .ClientID property of each control and put it into variables in a custom script that's easily accessible to the rest of the javascript on the page.

This should be easier than it is, and not having simple access to every control element from javascript is one of my complaints with the ASP.Net framework. They're doing a little to address this in the next version, though not as much as they could. In the mean time, you can find various components on the web that will help automate generating the script I described above.

Joel Coehoorn