Alex Rivera | Logout

How to get asp.net client id at external javascript file

Asked 2010-10-02T13:20:39.497
15

When I use embedded javascript functions I can get client id of elements with this code:

document.getElementById('<%=buttonXXX.ClientID%>' )

But now I am using external javascript file for caching and faster rendering and this code does not work any more for getting client id's of elements, it gives error.

How can I get client id's of elements at external javascript file using asp.net 2.0 , netframework 3.5 , c# , iis 7.5

Edit
Report

1 Answer

5

You could use a class selector. jquery might greatly simplify your life here. So you could apply a special class to the control:

<asp:LinkButton ID="foo" CssClass="foo" runat="server" Text="foo" />

and in your external javascript file once the DOM is ready you could reference the button using a class selector:

$(function() {
    var fooButton = $('.foo');
});
answered 2010-10-02T13:24:19.363

Your Answer