I have a user control and an image within that and I wish to execute some javascript when it;s clicked, in the Page_Load event of my user control I add the following:
imgCalendar.Attributes.Add("onclick", "displayDatePicker('" + txtCalendar.ClientID + "');");
So I’m adding an onclick event to imgCalendar and I want that event to fill in my text box txtCalendar with the output of my Javascript function displayDatePicker, it works perfectly fine in Internet Explorer but the click event does not fire in chrome, any ideas on why this is? are there any other ways I can add that click attribute to my image?
The problem was that the name of the text box control was chaning when the HTML was renderd, so the function:
displayDatePicker('uc1_txtCalendar')was getting called whereas the text box’s name (note that it’s name property not ID is used client side since an asp text box is rendered as a html input control) was rendered to ‘uc111$textCalender’, that ‘$’ thrown in in place of the underscore was the problem, I resolved this by giving everything a static ClientIDMode (for the text box and it’s container which in this case is the User Control)