views:

38

answers:

2

Suppose I have javascript within ASP.NET UserControl:

function setValue(DataItem) {
    var selectedDate = DataItem.getMember('DomainNameKey').get_object();
    Picker1.setSelectedDate(selectedDate);
}

Where Picker1 is also inside the control. Because Picker1's ID will be renamed at runtime, what do I put in the code below to make it work within a UserControl?

function setValue(DataItem) {
    var selectedDate = DataItem.getMember('DomainNameKey').get_object();
    <%= ?????????????? %>.setSelectedDate(selectedDate);
}
+2  A: 

You can use something like this:

function setValue(DataItem) {
    var selectedDate = DataItem.getMember('DomainNameKey').get_object();
    document.getElementById("<%= Picker1.ClientID %>").setSelectedDate(selectedDate);
}
Dean Harding
Although this should be the right answer... it doesn't work for my darn usercontrol. I think the UC is creating the control I need dynamically and therefore ASP can't find the dynamic control
MakerOfThings7
I suppose this is just something I need to finish w/the control vendor
MakerOfThings7
@MakerOfThings7: I think you might be right, there...
Dean Harding
A: 

In my situation, the ComponentArt controls create a second Javascript object that should be used. Read more here:

Q10103 - HOWTO: Determining the client ID of Web.UI controls in Master / Content pages http://www.componentart.com/kb/article.aspx?id=10103

Q10087 - HOWTO: Determining the client ID of Web.UI controls in user controls and templates http://www.componentart.com/kb/article.aspx?id=10087

MakerOfThings7