65.9K
CodeProject is changing. Read more.
Home

ASP.NET MasterPage getElementById

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

May 24, 2011

CPOL
viewsIcon

24954

To get an element by its ID in a webpage which uses a master page

We know that the id is changed when the page is rendered by ASP.net when using a masterpage. The id is then prefixed with the master pages name appended with an underscore. For examle: If one writes a text box with an id of 'txtDate' it will be rendered as 00$contePlaceholder1$_txtDate. It is difficult to attach a javascript functionality to this element, but using query we can achieve this quite simply by writing:
$("input[id$=txtDate"].DatePicker();
Here jQuery gets an element / array of element of type input(textbox) the name of which ends with txtDate and attaches a date picker. @author =NIBEESH K,STAB,DRDO,CVRDE