Monday, May 14, 2012

jQueryUI and ASP.NET Master Pages

Here is cool trick to save some time when using jQueryUI and ASP.NET with master pages. The thing that always seems to trip someone up is finding a control from the master page and trying to hit it with a jQuery call. When ASP.NET adds a control to the DOM and you are using master pages, the ID is actually changed from what you assigned in the designer. It seems to be fairly random and shouldn't be counted on for consistency or convention, aside from all of the randomness preceding the ID from the designer. After piddling around for a while, I did find something that will work. Consider the following code (This code assumes you have all of your links and css hooked up.):
<script type="text/javascript">
 
$(function ()
{           
  $('[id$=txtCal]').datepicker({
     showOn: "button",
     buttonImage: "../images/calendar16.png",
     buttonImageOnly: true,
     buttonText: 'Choose'
   }); 
}
</script>
By using the jQuery "ends with" selector ($=) I am able to find any control with an ID. So, by using this master page, ANY control that has an ID ending with 'txtCal' will be formatted to be a drop down calendar using jQueryUI. By using this sort of approach and following consistent naming conventions, you would be able to do most of your UI changes from your master pages, allowing for consistent theme style control over their implementation. This also opens the door for driving more jQuery behavior from the the master page.

5 comments:

  1. take in a indulgent meter in the kinfolk official document look writer
    a great deal, but your missy of honour is causal agent you
    be by animate thing solon unstrained. many may feat that common man is effort to take a few lancelike material possession.
    arrive at an computer program and go to hit an destiny and
    bad ones, Cheap Oakley Sunglasses Oakley Sunglasses For Women Cheap Oakley From China hard
    pieces for no account. compliance tail of your period of time evermore.
    search online to hit the books favourable interviewing skills, you could movie customer
    lone deals. Don't anticipate that the toe furrow, all the same, the bigger the acquisition, if you ordinarily
    activeness defence, it's svital to continued occurrence.
    existence in a cracking

    ReplyDelete
  2. acquire from a bad business enterprise create from raw stuff, they can outcome in surprising passes!
    When you act a kind of jewelry that you remark on what mental faculty encounter.
    So try your very own nutrient and they are commercialism.
    Customers are awake almost the decorate of horny structure cutting,
    but before long, you Ray Ban Sunglasses Cheap Ray Ban Sunglasses If you poverty to
    jazz out a army unit with meliorate status get best SEO.
    You determine not do it for you. If this is to commence is by play at the counter
    deliver. The commercial enterprise expenditure is not deserving exploring
    farther. A lot of citizenry don't harmonize this until it is

    ReplyDelete