Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
As far as web development goes, I came a little late to the party. I started life as a developer working on the absolute guts of a fairly complex object persistence engine. At my next stop I hand-coded an obscene number of business objects that fed our presentation layer (which is pretty ironic considering I just worked on an ORM!). Needless to say I didn't stay at that place too long. From there I finally took a stab at user interface when I took a gig as a WinForms developer. I did that for a little over a year and it was OK. Finally I ended up where I am now, about 60% of my day to day activities includes web developer on Microsoft's ASP.NET 2.0 platform. I did a little bit of web development with 1.1, but nothing substantial. Hands down, I enjoy web development the best (I have never once been complimented on how nice my LEFT OUTER JOIN looks).
When I started to work with ASP.NET 2.0, I had absolutely zero experience with HTML, JavaScript and CSS. Quite honestly, I found that you can get pretty far as an ASP.NET developer without too much knowledge of any of these. I interviewed for a good number of ASP.NET job's, and never once was I asked to
- Describe how the box model works
- Explain CSS selectors
- Discuss JavaScript's inheritance model
I am still no expert, but being knowledgeable in these areas is pretty much a prereq for building great web applications. So when the opportunity comes to dig deeper into one of these area's I usually take it. One of these came along last week. A business analyst was poking around on ComponentArt's web site and liked the look of a few of their controls. Specifically, they liked the shinny black border that surrounds their dialog and grid controls. So I did a little research to see what it would take to incorporate a similar border around our data grids and dialog controls.
The goal of the research was to create an HTML template that included the markup and CSS classes that we could use to surround our existing data grids and popup controls to get a similar look and feel. Below is a screen shot from the sample I created. The grid is live so you can page and sort the data. Also, there is a slider on the page that you can use to adjust the width of the grid (this demonstrates the fluidness of the border). The second demo shows Delete Confirm and Tip of the Day popup controls that use this border as well.
Live Data Grid Demo (IE6, IE7 and FF) | Live Popup Demo (IE6, IE7 and FF) | Download (.Net 3.5 and AJCT 3.5.11119.0)
HTML Structure and CSS Classes
Like I said earlier, I wanted to create an HTML structure that I could surround both my data grids (GridViews and for this sample a ListView) and popup panels with. So to create the border template, I created an HTML structure that divided the container into 3 regions: header, body and footer. Each of these 3 regions was further subdivided into 3 sub-regions: outer, inner and content. For each of the regions, the outer class is used to apply the right hand border, the inner class is used to apply the left hand border, and the content is used to apply the background. This is similar to the approach the AjaxControlToolkit's TabPanel uses to provide the nice rounded borders for each of the tab headers.
Here is the markup that builds the header structure.
Here are the images that make up the header.
And finally, here are the CSS rules that apply these images.
I used the sample template for both the footer and the body and as a result I came up with the following HTML structure.
Adding the Border to a DataGrid
Applying this border to the ListView/DataPager/Slider example I created previously was really simple. I just moved the ListView into the body's content region like so. That's it.
Adding the Border to a Delete Confirm Popup Control
Besides surrounding a data grid, I also wanted to apply the same template to our delete confirm popup panel. Because our popup panel also currently support dragging, I also wanted to include this feature as well. So I tweaked the template and replaced the dialog and header DIV's with asp:Panels so the DragPanel control would have something to attach to. If you haven't used the DargPanel before, it is simple - there are really only 2 attributes you have to worry about!
I also added a close button to the upper right hand corner of the dialog. Additionally, I added a section to the body for the OK and Cancel buttons. Here is the markup for the Delete Confirm sample dialog. Below that is what it looks like.
Adding the Border to a Tip of the Day Dialog
For good measure, I also applied this template to the Tip of the Day dialog I previously blogged about. Again, I wanted to support dragging, so just like with the Delete Confirm example, I replaced the containing DIV with an asp:Panel as well as the header DIV. Additionally, I wanted to use the DynamicPopulate extender to replace the tip with the response from a web service. So again, I added an asp:Panel to the body's content and this is what the DynamicPopulate replaces with the webservice result.
Here is the markup I used for the Tip of the Day dialog, below that is the markup for the PopupControl, DragPanel and DynamicPopulate extender controls. Lastly, is a screenshot of what the control looks like.
That's it. Enjoy!
Comments
Hi Matt,
Continuing your good work hmmm....
As I am new to asp.net, I dont know much about custom control.
Can you give some hints how to create a custom control like Tip of the Day, in which we can handle "Closed" event on client side as well as server side, when user clicks either "x" or Close button
Thanks.
Excellend!
Again a great post and great example markup to use as a base for own projects. I really enjoy your posts, keep up the good work!
Another great post, you hunting for a MVP award?
Sweetness! The only thing I would recommend is to take advantage of the PNG image format benefits. The corners on the dialogs are not transparent, so if you pop that dialog up on a page that has a background color/image that is not pure white, the corners will noticeably stick out. While that is somewhat difficult to notice in this particular becuase of the small size of the corners, I still feel transparency would have made this flawless.
You could also create an accurately fading drop shadow effect that would really make those dialogs dazzling. Such things are super simple in Adobe Photoshop, and can also be done using free programs such as Paint.NET.
Best regards...
Awsome
Hey Matt:
U rock!!!
Regards,
Swami
Thanks for the feedback everyone, I appreciate it.
@Josh -
Great comment. You are absolutely right.
@Tim -
I certainly wouldn't turn one down ;)
@Vish
No problem. If you drop me an email, we can discuss this further
Matt.
Nice, too bad it needs so much markup. You know what I have noticed on your blog? You have nice examples, but they are not portable at all (i.e. require copy/paste typing for each page over and over again). You should consider wrapping stuff like this up into controls (or control extenders) and releasing it on codeplex.
@Mike -
Good feedback.
You are right. This would make a good candidate for a server side control.
Matt.
Matt, your blog is a real eye opener and always such a pleasure to read.
foreach (posting post in Matt.posts) { PayMattMoreMoneyForPost(post); }
:P
So I'm quite new to CSS and haven't tweaked this to see the difference, but why are the inner and content div's children of the outer div. I would have thought they would be peers...?? Just curious.
Great stuff, btw. Always enjoy learning new things here.
Awesome... Bring the Bling!
the result looks pretty impressive, but when I see the enormous amount of nested div-tags the I gat the feeling that div-tag-soup is replacing table-tag-soup on the menu.
I think it must be possible to drop a couple of the div-tags.
For starters you could look at the 'sliding doors' principle.
then you could also try to use the elements within the div as part of the styling solution. Like the h2 tag inside a div gives you enough markup to create header for your dialogs.
@Rob Hofker -
Good point. If I combined the right and middle background images for the top and bottom I should be able to loose a few of the DIV's.
Thanks,
Matt
Any idea about the differences between AJCT's 3.5.11119.0 and 3.0.11119.0?
Hi Matt,
thanks for the post!
but i have one question may be simple one
when i click on on "Delete Confirm" i want the background to be disabled, so that user wont click any other button....how would i do that?
thanks.
Hi Matt,
There is an unpleasant thing.
I used Internet Explorer 7.
Please run Live Data Grid Demo
Please repeat items 1 and 2 a few times.
Image will be running.
How to avoid this unpleasant effect?
Any ideas?
Hi Matt,
It is great to learn new things from ur site, continue the good work. However i would like to know if v could have a gridview with search option as onkey over (example can be viewed in component art demo grid
view section)
thanks
pls let me know if it is possible.
Hi Nisar,
When you hold click and then rotate the wheel on the mouse - this is a command to zoom IE window.
You can verify the same by looking magnifier icon, which appears on the status bar.
Hope this helps.
Saurabh Verma
http://www.domaindrivendesign.info
learn and share
Great Article
Hi Matt,
If the width of inner data table (ListView or GridView) is more than 700px the surrounding panel remain static and don't follow the inner content. It's possible to have a dynamic width of surrounding panel according to the content of inner data table?