jQuery UI – Resizable w/ ASP.NET Themes

flwr-083 If you’ve been up to the jQuery web site and looked at the documentation for resizable() you probably thought, “hey, no problem, I can do that.”  Well, that’s what I thought, too, until I started using it.

Here’s what you need to know to get this all working–and specifically, what you need to know to get it working under ASP.NET.

First, as you would expect, you’ll need to create some html on a page that has a div tag that you can select with a jQuery selector statement.  I just gave mine an id of “sizeMe”:

<body>
    <form id="form1" runat="server">
    <div style="height:100%; width: 100%;">
    <div id="sizeMe">
        <p>Here is some text</p></div>
    </div>
    </form>
</body>

Then you’ll need to use the jQuery selector and call resizable() in the ready() handler:

$(function() {
    $("#sizeMe").resizable();
});

And as they say on TV, “But wait, there’s more…”

Because the part we kind of glossed over in our work is that the jQuery UI has themes that you can apply.  This is a set of CSS files and images that we can copy into our ASP.NET app_Themes/themeName directory.  To style these widgets.  We need a theme so that the cursor will change for the edges and so that we get the grab handle in the corner of the div we’ve marked for resizing.

When you download the zip file from the jQuery UI site make sure you choose a style and you copy the stuff in the theme directory of the jQuery UI zip file into your theme directory of your ASP.NET web application.

You’ll notice that there several CSS files that are part of this set.  And you’d think that since they are in the theme directory that they’d automatically get sucked into any ASPX page we had attached to the theme.  Well, if that’s what you are thinking, you’d be wrong.

I don’t know if it’s by design or if it’s an “undocumented feature,” but it looks like any file that has multiple “.” in it will treat the first “.” as the starting point for the extension when .NET processes the files in the theme directory.  Because all of the jQuery CSS files are named ui.something.css, these files will not get sucked in automatically.

That’s actually good news because if it did suck them in for us, we’d end up sucking them in twice or we’d need to remove the us.all.css file.  But since they aren’t automatically processed, what we are going to do is place the following statement in the top of our main css file for our web site:

@import "ui.all.css";

And that folks, is the magic that makes this all work under ASP.NET.

Once you have the themes installed correctly, the html and javascript will do their thing and you can finally resize your div like you would expect to be able to.

I also note that it is pretty cool that jQuery themes work so nicely with ASP.NET themes.  This means that just by switching theme directories at the ASP.NET level we can switch our jQuery UI themes as well.

 

Other post in jQuery

Related Post

3 Responses to “jQuery UI – Resizable w/ ASP.NET Themes”

  • [...] jQuery UI – Resizable w/ ASP.NET Themes (Dave M. Bush) [...]

  • Ted:

    Hi, Thanks for the info…

    When you say
    @import ui.all.css

    Do you mean @import ui.*.css

    Not sure…

    I was looking for help as it seems whenever I edit source/markup in VS 2008 my project seems to cycle through loading all the .css file’s over a few times– it’s a bit of a problem when editing a site via my wireless connection. I have to wait while all the .css files are reloaded over and over.

    I’m loading jquery from my masterpage (.NET 3.5 SP1 + JQuery intellisense hotfix) via the scriptmanager, I’m having trouble in VS 2008 with JScript intellisense error (within the jquery-1.3.2.js file also)

    I’m also using App_Themes\MyTheme etc to house all my .css

    The website works fine, just a bother in VS-2008.

    I think the fact that there’s an Intellisense error in the jquery-1.3.2.js file is causing to problem. It’s as if all my .css files are not cached and every time I edit a page, it looks to reload my .css files.

    Any ideas?

    Should I not use Scriptmanager to load the JQuery/JQueryUI and blockUI ?

  • Dave:

    No, I meant what I wrote. But I wrote this prior to jquery 1.3.x so you may not have an ui.all.css file anymore. Last time I got the CSS for the UI stuff it was all in one CSS file. The only reason for the import statement is because VS2008 can’t see css files that have dots prior to the css extension. So, it won’t load them automatically.

    You should be developing on your local machine. Not on some other computer over the Internet.

    No, I don’t use the script manager.

    I have seen the intellisense error on one of my computers but not my main one. I’m not sure what the fix is yet but I’m quite sure it has nothing to do with CSS. In fact only jquery ui uses the CSS.

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail

Bear