August 2003 - Posts

Dialog Hell

ASP.NET is a great tool, but it definately has its limitations. One of those limitations is the fact that it has no built in support for any kind of UI that uses dialogs. I assume that if you have been using ASP.NET for a decent amount of time, you have run into this problem more than once.

At the base level, the problem is pretty simple to solve, but if you have a lot of dialogs in your application, you can wind up writing a lot of extra code just to get things working. This isn't even to mention that things go from bad to worse if you want your dialogs to function like real dialogs (ie. they are reusable, so you can launch, wait for the user to select an item, and then do something based off of that selection back in the code behind for the page that launched the dialog).

While building our ASP.NET based CMS (<shameless_plug>a very cool product which is due for release in the near future</shameless_plug>), it quickly became aparent that all the JavaScript coding that we were doing was quite redundant and was quite a pain. So, I put together a few classes to handle most of the basic dialog functionality. If you are in the same type of situation, you may find these classes useful. Basically, there is one base class that can be used to create a draggable dialog control (Dialog). This class basically handles launching the dialog and processing the return results (an “Open“ function is included to create the JS launch script for your dialog). The second class, “DialogPage“ serves as the base page class for your dialogs (just change inheritance on the Page class in your code behind file). It contains a few helper methods to close the window and return results. A third class, PostBackHandler is a stripped down control with no UI that allows you to handle the results of the dialog via a PostBack event. Using this type of approach definately makes working with the custom dialogs in your project a lot more developer-friendly (not to mention that you can extend the base classes to have things like modal dialog support, and all your dialogs will be automatically upgraded).

public abstract class Dialog : Control, INamingContainer

{

public Dialog()

{

pbhDialogHandler.ID = "pbhDialogHandler";

pbhDialogHandler.PostBack+=

new PostBackEventHandler(pbhDialogHandler_PostBack);

Controls.Add(pbhDialogHandler);

}

protected override void OnPreRender(EventArgs e)

{

base.OnPreRender (e);

Page.RegisterStartupScript("__dialog","<script>function __processDialogResults(controlID, results) { __doPostBack(controlID,results); }</script>");

}

PostBackHandler pbhDialogHandler =

new PostBackHandler();

protected override void CreateChildControls()

{

base.CreateChildControls ();

}

void pbhDialogHandler_PostBack(object sender, PostBackEventArgs e)

{

ProcessDialogResults(e.EventArgument);

}

protected virtual void ProcessDialogResults(string results)

{

}

protected void Open(string windowName, string url, int width, int height)

{

if(url.StartsWith("~/"))

{

url = Page.Request.ApplicationPath+"/"+url.Substring(2);

}

if(url.IndexOf("?") == -1)

{

url = url+"?ControlID="+HttpUtility.UrlEncode(

this.pbhDialogHandler.UniqueID.Replace(":","$"));

}

else

{

url = url+"&ControlID="+HttpUtility.UrlEncode(

this.pbhDialogHandler.UniqueID.Replace(":","$"));

}

Page.RegisterStartupScript("__open", "<script>window.open('"+url+"', '"+windowName+"', 'width="+width+", height="+height+", scrollbars=no, resizable=no, toolbar=no, location=no,menubar=no, directories=no');</script>");

}

public abstract void ShowDialog();

}

public abstract class DialogPage : Page

{

public DialogPage()

{

}

string ControlID

{

get

{

return HttpUtility.UrlDecode(Request["ControlID"]);

}

}

protected void Close(string results)

{

Page.RegisterStartupScript("__close", "<script>window.opener.__processDialogResults('"+ControlID+"',\""+results.Replace("\"", "\\\"")+"\"); window.close();</script>");

}

protected void Close()

{

Page.RegisterStartupScript("__close", "<script>window.close();</script>");

}

}

public class PostBackEventArgs

{

string eventArgument;

public string EventArgument

{

get

{

return eventArgument;

}

set

{

eventArgument=

value;

}

}

}

public delegate void PostBackEventHandler(object sender, PostBackEventArgs e);

public class PostBackHandler : Control, IPostBackEventHandler

{

public PostBackHandler()

{

}

public event PostBackEventHandler PostBack;

#region

IPostBackEventHandler Members

public void RaisePostBackEvent(string eventArgument)

{

PostBackEventArgs e =

new PostBackEventArgs();

e.EventArgument = eventArgument;

if(PostBack != null)

{

PostBack(

this, e);

}

}

#endregion

}

Posted by Jesse Ezell with 18 comment(s)

Not More Datagrid Nonsense...?!

Julia points out that there is a new .NET rocks show up at Franklins.net.

Marcy seems like a great girl, but maybe some day, they will interview XML Boy or Patterns Man, so I can justify the hour away from real work...

Posted by Jesse Ezell with 20 comment(s)

Flash 2004

I need to stop blogging, Macromedia is catching on...

Flash 7 will include (among other things), 2x-10x performance gains, VSS support, OO inside of Actionscript, and Forms based layout / design. Additionally, Royale will add support for declarative (JSP/ASPX style) flash presentations... Yah, this is all pre-launch hype, but it does sound like a significant improvement...

Posted by Jesse Ezell with 6 comment(s)

SCO Code?

For those who don't get news from outside their aggregator anymore...

“Sontag also said thousands of lines of Unix have made their way into Linux in the form of derivative works that should have been bound by SCO licensing agreements that require licensees to keep the code secret. The company said several enterprise features of Linux--the NUMA (nonuniform memory access), RCU (read-copy update), SMP (symmetrical multiprocessing), schedulers, JFS (journal file system) and XFS (extended file system) portions--all include copied code. The company broke out the number of lines of code that had been directly copied from each. It said, for example, that more than 829,000 lines of SMP code had been duplicated in Linux”
[ZDNET]

Posted by Jesse Ezell with 3 comment(s)

Checked Exceptions

Scott W points out part 1 of the Anders interview. The second part is pretty good too:

“Frankly, they look really great up front, and there's nothing wrong with the idea. I completely agree that checked exceptions are a wonderful feature. It's just that particular implementations can be problematic. By implementing checked exceptions the way it's done in Java, for example, I think you just take one set of problems and trade them for another set of problems. In the end it's not clear to me that you actually make life any easier. You just make it different...

C# is basically silent on the checked exceptions issue. Once a better solution is known—and trust me we continue to think about it—we can go back and actually put something in place. I'm a strong believer that if you don't have anything right to say, or anything that moves the art forward, then you'd better just be completely silent and neutral, as opposed to trying to lay out a framework.

If you ask beginning programmers to write a calendar control, they often think to themselves, "Oh, I'm going to write the world's best calendar control! It's going to be polymorphic with respect to the kind of calendar. It will have displayers, and mungers, and this, that, and the other." They need to ship a calendar application in two months. They put all this infrastructure into place in the control, and then spend two days writing a crappy calendar application on top of it. They'll think, "In the next version of the application, I'm going to do so much more."

Once they start thinking about how they're actually going to implement all of these other concretizations of their abstract design, however, it turns out that their design is completely wrong. And now they've painted themself into a corner, and they have to throw the whole thing out. I have seen that over and over. I'm a strong believer in being minimalistic. Unless you actually are going to solve the general problem, don't try and put in place a framework for solving a specific one, because you don't know what that framework should look like. ”

Posted by Jesse Ezell with no comments

If a windows update dialog pops up on an abondoned machine, does it make a sound?

Looks like Martin forgot to patch...

I got it too on my desktop at the office... I never use that thing, so it never ends up getting patched. Since I use my laptop for 100% of the work I do, it basically just sits there are collects dust. Come to think of it, I probably wouldn't have even known it was infected for another 6 months or so if it hadn't started rebooting every 10 seconds...

Of course, this is always how viruses end up coming in to the office, some machine on the network that no one ever uses, so patches never get installed... You think we would have got smart after nimda... nah... when it comes to machines we rarely use, we are just as lazy as the admins who don't patch their servers.

 

Posted by Jesse Ezell with 5 comment(s)

Money Grubbing Bastards

Charting components are way too expensive. You basically have one of two options: purchase a half-baked, lousy component that produces charts designed by your local elementry school's brightest, or shell out an endless revenue stream to the money grubbing bastards at Software FX or Dundas. Well, of course, this is only if you are creating an ASP.NET app. If you are creating a Windows Forms app, our friends at Software FX will give you a license to redistribute the code on a royalty free basis. But this doesn't apply to web apps for some strange reason... you need to dish out cash every time you sell your product. This is utter nonsense (especially considering that each license costs $1500 before any OEM deals)...

Of course, this is what is wrong with the 3rd party component industry these days. If it wasn't for the high prices and low quality of American made components, maybe we wouldn't have to ship our jobs off to India...

Update from Thomas: The guys at Infragistics aren't money grubbing bastards. Checked out their license. Much cooler:

“Server-side components are licensed DEPLOYMENT FREE. You pay to use them in design time. You do not pay per-server deployment fees when you deploy your application.“

So, guess who's components I will be using. Not quite as pretty, but it does what I need it to do. :-).

Posted by Jesse Ezell with 11 comment(s)

DHTML is Better... Told You So

jd (Macromedian) points out this post by Tim Bray:

“At Antarctica, for version 3.0 of Visual Net, we added a Flash-based user interface to our traditional HTML flavor. For 4.0, which ships sometime before end-of-year, we’ll be backing it out and sticking to dynamic HTML. It’s the right thing to do, but the choice wasn’t a slam-dunk...we found that real customers doing real installations ended up going for the HTML version every time.“

Two main reasons were browser integration and speed. #1 isn't such a huge deal from my point of view, as JD points out, you can integrate the back buttons with anchors (but this only works in MX). Still, the 2nd is the main problem. As Tim points out, the common theory is that your app will perform better with a flash based UI, because you are only sending data back and forth, which gets parsed by the UI, and then rendered on the screen (instead of performing all the rendering logic server side). However, the fact of the matter is that Flash chokes when parsing XML (similar to calling a web service from a .NET CF app). Still, this isn't the only problem. The UI rendering is slow as hell, so even if you overcome the XML loading problems, you have a major usability problem (once again, I point to Lazslo as a good example of this). When using DHTML, the rendering is lightning fast, and you can databind your XML on the server side if the client can't handle processing it for some strange reason (which isn't going to be the case in my experience, unless you are doing downlevel stuff).

Posted by Jesse Ezell with 1 comment(s)

Working for Microsoft

This is the latest post in the “how can I get a job at MS” speculation series. He isn't the first person to comment about this (heck, Sells was talking about it for years before he finally got the guts to go get an interview). Personally, I fail to see what is so scary about getting a job at MS, or why people plan out how they are going to get in for 10 years before finally getting an interview. Microsoft is hiring like crazy right now, there is no gaurentee that will be happening even 5 years from now, so anyone interested in working for them should stop scheming, suck it up, and set up an interview this week. If you don't get hired, big deal. Brush up your skills and get another interview for a different position (or, interview at another company... MS isn't the only cool software company out there).

Posted by Jesse Ezell with 5 comment(s)

ObjectSpaces

Interesting post and discussion from our Java friends over at TheServerSide:

“Microsoft has published their 2003-2005 developer tools roadmap which mentions that .NET 2004 will include Objectspaces, an object oriented transparent persistence framework, much like our own JDO. Might this development finally convince the J2EE vendors (especially Sun) that transparent persistence really matters?”
[TheServerSide]

Posted by Jesse Ezell with 1 comment(s)
More Posts Next page »