Click here to Skip to main content
15,884,298 members
Articles / Web Development / ASP.NET
Tip/Trick

ASP.NET MasterPage getElementById

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
26 May 2011CPOL 24.5K   4   2
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:

JavaScript
$("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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralJQuery Pin
Hariharan Arunachalam25-May-11 18:22
Hariharan Arunachalam25-May-11 18:22 
This qualifies as a piece of jQuery code snippet. Doesn't actually qualify for anything.
GeneralNeeds some work Pin
Richard MacCutchan25-May-11 0:52
mveRichard MacCutchan25-May-11 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.