Linked by Will Senn on Thu 22nd Apr 2004 06:30 UTC
General Development This article is intended to give you a practical recipe for creating a simple Web Control and extending Visual Studio with support for the control. The control itself is a basic Country Code drop down list such as you would find on many profile entry pages.
E-mail Print r 0   · Read More · 28 Comment(s)
Order by: Score:
v Nice tutorial
by Zeke on Thu 22nd Apr 2004 07:06 UTC
Good Introduction
by JCooper on Thu 22nd Apr 2004 13:30 UTC

An excellent introduction into creating custom controls in aspx solutions. I'd like to see more of these available as learning points - asp.net is kind of a different mindset to php.

What I liked most...
by Kyle on Thu 22nd Apr 2004 14:29 UTC

8.3. FlowLayout Positioning
Visual Studio defaults to GridLayout for .aspx files. Change it to FlowLayout. The difference is that GridLayout uses absolution pixel positioning (Grid) and FlowLayout uses relative positioning (Flow, things get put next to each other). To change the layout, Click over to the HTML view of default.aspx and change the MS_POSITIONING body attribute to FlowLayout:

<body MS_POSITIONING="FlowLayout">


This is really important for cross browser compatibility. GridLayout is a PITA. It doesn't work in most browsers and is only reliable in IE. It attempts to turn a web page into a form type design. To me, it feels like a way to help move program designers to web design. Switching to FlowLayout is much better.

Then again, all HTML/CSS support in VS.net/ASP.net is pretty horrid in general.

Highlights a weakness of MS's view of the web
by Kyle on Thu 22nd Apr 2004 14:34 UTC

It's amazing to see how much work is involved in creating a custom control for the web. It is a real weakness of applying a programming model to the web, when clearly a plain text/scripting combination is much better.

I've done a couple of controls this week, and I wish I could use PHP. Something I could do in a 1/2 hour in PHP turns into a 4-8 hour charade with ASP.Net/C#. To do this control in PHP is much faster and easier. Microsoft has made it way too complex.

This article is well written and will help a lot of people.

IE-Monopoly
by blk on Thu 22nd Apr 2004 15:29 UTC

"It doesn't work in most browsers and is only reliable in IE" - typical for MS, 1. they think that W3C isn't for them and 2. they "oblige" Win users to stick with IE (or just not have things working) - ... again one step to maintain the monopoly

and i agree PHP is more adequate, it also uses less ressources than the overloaded .NET framework

RE: IE-monopoly
by Rodrigo on Thu 22nd Apr 2004 15:54 UTC

and i agree PHP is more adequate, it also uses less resources than the overloaded .NET framework

Still I think ASP.Net might have some advantages over PHP, such as full OO, JIT compiling, code-behind, etc, doesn't it? I suppose this pays off some eventual extra cost one might have to put more "server resources" available.

I've used both ASP.net and PHP (as well as Cold Fusion, old ASP and whatever the customers had on their sites) and I would prefer ASP.Net over anything else any day, the productivity I got with .Net is simply amazing. Actually it's the first time in many, _many_ years that I saw something from MS and I thought "Gee this is very good!". ASP + COM was miserable.

But maybe it's just me, I don't wanna "convert" anyone or start flame wars.

About the GridLayout thing: I hope they get rid of it on VS.Net 2005, I'm yet to see anyone who uses that.

RE: RE: IE-monopoly
by Gabriel Ebner on Thu 22nd Apr 2004 16:21 UTC

> advantages over PHP, such as full OO, ...

If you need this all then write a CGI script. It has less overhead as the previous poster (presumably) meant.

PHP????
by Anonymous on Thu 22nd Apr 2004 17:04 UTC

Wow. I can't believe people are seriously comparing PHP to this. I'll admit that I was a PHP programmer back in high school. Then I taught myself J2EE and enterprise-scale web application design patterns. Now PHP seems a horrid kludge useful only for creating simple personal web pages.

I haven't done any ASP.NET programming, but industry seems to hold it in the same regard as J2EE. This custom control idea seems analogous to custom tags in JSP. There is nothing like it in PHP. Suppose you want to validate input coming from your custom control. You can probably (again, I don't know ASP.NET) attach validation code to the control. Then your other developers can use that control anywhere on the website just by dragging and dropping it in. In PHP, you would have to encapsulate rendering the control and validating the control in separate functions and call those functions directly on the web page, placing the validation call at the top and the rendering somewhere in the body, and you would have to remember to copy and paste both of those every time. MVC is nigh near impossible in PHP.

As for CGI having less overhead than ASP.NET, you've got to be kidding. It has a smaller fixed cost, sure, but the per-request hit is humongous as you have to fork another process every time. You will not find enterprise web development jobs using PHP or CGI because of poor scalability both in terms of development and in terms of handling requests. See http://www.onjava.com/pub/a/onjava/2003/06/04/nukes.html for a case study.

Dev Yes! Deploy?
by erktrek on Thu 22nd Apr 2004 17:59 UTC

My main issue with VS is that, behind the scenes it likes to add a whole lot of extra things (extra files/folders& FP extensions) to your website which may or may not be necessary.

You can run ASP.Net fine with just aspx/cs files and maybe a "bin" dir for your .net DLLs. Even if you add a config (asax) file or two things are still pretty tight.

Admittedly I prefer a simpler structure because it is easier for me (and my little brain) to keep track of exactly what is going on and troubleshoot. Also I suspect it makes the site more portable.

Having said that I do think the interface & debugging capabilities are excellent.

My .02 - ymmv


E.

Re: Dev Yes! Deploy?
by Rodrigo on Thu 22nd Apr 2004 18:10 UTC

I think MS also recognizes things are a bit overkill. On the next version of VS.Net they'll make things a bit easier, they learned a thing or two with ASP.Net Web Matrix, I suppose...

For example it won't be necessary anymore to create project files, solutions, etc, you just put the aspx files in a folder and that's it, like it used to be with ASP.

My 2 øre anyway ;)

RE: Dev Yes! Deploy?
by gonzo on Thu 22nd Apr 2004 18:43 UTC

Visual Studio 2003:
Go to Solution Explorer and Select your project. Click "Copy Project" icon (in Solution Explorer). Select "Only files needed to run this application" and Click OK. Set path to where you want your project deployed and.. that's it. Complicated?

RE: PHP????
by Keith on Thu 22nd Apr 2004 18:55 UTC

You will not find enterprise web development jobs using PHP or CGI because of poor scalability both in terms of development and in terms of handling requests. See http://www.onjava.com/pub/a/onjava/2003/06/04/nukes.html for a case study.

Don't base the speed of PHP on a single, overly complex, completely bloated, slow, etc.... CMS like postnuke. I have to deal with slow Java based web apps all the time, does that mean Java is slow? No, it means the programmers behind the programs didn't do a very good job. I have seen ASP.Net apps ported to PHP that run 4-5 times faster. So not only do you gain speed, but you can also loose the server farm and the load balancers it took to run the ASP app. Again, this might just have been a poorly written ASP app. Also, I wonder if Yahoo using PHP would count as an "enterprise web development job". I never used ASP.Net but I used ASP all the time before I moved to a Unix/NetWare shop. The beauty of PHP is its simplicity. Use it for fast and easy procedural apps, or create a nice framework to work off of, you can do both, with the same language. You can't take the complexity out of ASP or Java.

Keith

RE: RE: PHP????
by Anonymous on Thu 22nd Apr 2004 19:28 UTC

Scalability with PHP is hard. As I understand it, Yahoo! uses a C++ backend to do much of the work and uses PHP in the presentation tier. PHP doesn't even have connection pooling, so using it below the presentation tier seems to be a bad idea. Also, http://dada.perl.it/shootout/craps.html shows that Java is 35% faster at performing logic once you've gotten the data.

I agree that PHP is fine for simple personal web page type stuff, but for larger web applications, J2EE has established frameworks based on proven design patterns that increase productivity for development teams, and you can use it for everything above the data-server tier.

re: Nice tutorial by Zeke - moderated down
by Will Senn on Thu 22nd Apr 2004 23:26 UTC

Yeah, I know it was long and detailed - but it was meant to be comprehensive - a beginner's tutorial. The intermediate folks will have to scan the easy stuff to get to the meat.

Thanks,

Will

re: What I liked most...
by Will Senn on Thu 22nd Apr 2004 23:28 UTC

You said it! FlowLayout is the only way to tame cross browser layouts. Not only that but once, MS starts putting absolute positions all over the place the HTML starts to look like spaghetti.

Thanks,

Will

re:Highlights a weakness of MS's view of the web
by Will Senn on Thu 22nd Apr 2004 23:33 UTC

Well, not really... The bulk of the work was in hooking up the custom control to the design view, not in actually making a user control.

RE: IE-monopoly
by Will Senn on Thu 22nd Apr 2004 23:35 UTC

You are correct .NET will scale very well in enterprise situations if not in a mom & pop web site. Code behind is absolute genius.

regarding FlowLayout, enough cannot be said - and Grid's the default? what were they thinking?

Will

re: Dev Yes! Deploy?
by Will Senn on Thu 22nd Apr 2004 23:40 UTC

One thing you can always do is use UltraEdit/Textpad and the command line compiler to create your code files and only use Studio for debugging... I'm going to write an article on Web Services with Notepad that details the minimum necessary to write a web service from scratch using tools provided by the framework itself without requiring VS. Pretty much any project can be written without relying on Studio (it's just quicker/easier once you figure out the cruft from the meat).

Later,

Will

@Senn.
by erktrek on Fri 23rd Apr 2004 02:15 UTC

Yes I agree! In fact I use Homesite & TextPad (love that columnar copying/pasting) and have been trying my hand at creating Dlls in Sharpdevelop. I do like the technology. I'm excited about the cross platform possibilities. Apache/Mono/Linux anyone?

Gonzo mentioned earlier that I could easily deploy only the working files. I'll have to check that out. The only issue I have with that though is that the differences between my dev and live environments then becomes greater increasing potential for errors. Also I kinda like to keep my dev stuff clean too..

Thanks for the article btw.

E.

@erktrek
by gonzo on Fri 23rd Apr 2004 03:13 UTC

The only issue I have with that though is that the differences between my dev and live environments then becomes greater increasing potential for errors.

Or decreasing it perhaps?

Look, you develop on your dev machine and test it there too. Then you deploy it to your test server and test it there. Once it works, deploy it to your main server and that's it. Isn't that the whole point of having separated dev and production boxes - so that you can deploy only well-tested application to your production server?

re: @Senn.
by Will Senn on Fri 23rd Apr 2004 04:30 UTC

Thanks for the compliment. I am excited about the mono front as well, although the documentation is seriously slim for running it in a windows environment - in linux it apparently works pretty well. In Windows - hmmm... I had to copy mscorlib.dll to C:binstalllib to get it to run (apparently it was hard coded in mono - and then gtksharp - ow! I'm sad to say I had to give up on getting that to work in windows...

Will

@erktrek
by rod on Fri 23rd Apr 2004 10:16 UTC

Yes I agree! In fact I use Homesite & TextPad (love that columnar copying/pasting)

You can do columnar selection on VS.Net too, just hold the ALT key.

re:@erktrek
by Will Senn on Fri 23rd Apr 2004 13:07 UTC

columnar selection, sure.. but what about, hex mode, wordwrap off, view in browser, send in email, line folding, sort, convert formats, upcase, lowcase, mixcase, on and on and on? I like VS, but it's editor is very, very weak (other than intellisense and code folding).

On another related note, one thing that I wish the VS environment supported is the full gamut of file selection from the context menu - ie. when you right click on myWebservice.asmx, you would be able to edit the .asmx in text mode, design mode, and the .asmx.cs code behind file by selection - as it is you can't even get to the text mode of the .asmx file without explicitly opening it in source(text) mode.... The navigation between all of these different views/formats is very clunky - I hope it improves in 2005...

will

@will senn
by Rodrigo on Fri 23rd Apr 2004 19:31 UTC

- Hex mode? never needed that lately, but maybe it's just me.
- wordwrap: you have it (check tools/options/text editor).
- view in browser: for me "run" works good enough, but you also find this option on the context menu
- line folding: it's there
- send in email: well the email client is sitting there on the taskbar already ;)
- upcase, lowercase: there
- view file in text mode: right click, "open with...", select notepad...actually you could do that for an hex editor too ;)

Anyway..you know you can creates macros for the missing stuff, right? ;)

re:@will senn
by Anonymous on Fri 23rd Apr 2004 23:05 UTC

Rodrigo,

Sure it's 'there'... somewhere... or I could 'write a macro' - or in UltraEdit, just press the button or key to do it. I think we aren't talking about the same things, though - you are talking in terms of Code editing only, I'm talking about all code related editing. For example, let's say you are reading a string from the database and writing it to xml - you log the string that you are writing to xml in a text log file - another program is reading the xml and complaining that it's invalid xml at character 92, line 40. You bring up the log file in VS - looks fine - what's going on? No telling, bring up UltraEdit and look at the line - looks fine, what's going on? Click Hex and lo and behold some snark has added an emdash (non-ascii character that looks like an ascii '-') to the data in the database.

You are correct that if you dig deeply enough into the capabilities of Studio's editing facilities, that it's got a lot of the same functionality - it's just not nearly as accessible and carries a ton of overhead - takes it forever to start up - less than a sec for UE or Textpad. I'm not trying to start a flamewar here, either. I use VS's editor for writing code - like I said intellisense is great, but as all around editor - forget it...

Will

@will
by Rodrigo on Fri 23rd Apr 2004 23:39 UTC

OK sorry if I got it wrong, it seemed to me that you were saying these features didn't exist at all.

Having said that, I agree that VS.Net is far from perfect (for example the CSS editor inside vs.net sux big time, I keep using the one bundled with Homesite instead) but then again I haven't find a perfect editor.

Anyway, I didn't want to start any kind of flamewar, if I consider "language wars" stupid, what to say about "editor wars"! ;)

-R

cost
by CS on Sat 24th Apr 2004 17:08 UTC

Language and editor wars aside, it takes me twice as long and costs 10 times as much to develop, manage and host in VS.Net/ASP.Net/C#.

In the real world, that hurts a lot. People don't have the budget these days for sites which cost thoussands of dollars/pounds.

I am a MCSD but I develop using Textpad, Postgres, PHP and OpenBSD...

re:cost
by Will Senn on Sat 24th Apr 2004 22:43 UTC

I get what you're saying in principle, but in practice - where are you calculating the 'cost'?

Developing in ASP.NET/C# actually don't have to cost a red cent (other than effort) - the SDK is free. Studio is expensive, yes, but it's not required to develop apps. Postgres works well enough with .NET, although MySQL offers a driver that will (in theory) outperform it using ADO.NET.
The Server is where I calculate most of the 'cost' and it's not radically expensive to host a website with IIS, these days.

On the twice as fast using other tools comment, that's been your experience I take it? VS.NET most definitely supports RAD and applications from simple mom and pop ecommerce sites to complex search, catalog and financial websites can be rapidly constructed using it. Experience is the best teacher... For example, Multi-tiered architectures are cool to read about and can entertain a group of Comp-Sci students, but are rarely required in the majority of 'real world' situations - at least to the degree that they are hyped. The concept is sound and should be strived for at times, but generally an interface, database, and logic are what's required to service a small-medium size website. How much separation there is, is a matter of no small consideration. However, unless you are developing an enterprise solution - less is more. The default codebehind separation of interface from logic is sufficient. The logic and data objects can be hand written by a proficient developer without introducing an additional hierarchy of classes, separated by more file boundaries. I guess what I'm saying is that I can write a Web Application in .NET that reads some data from a DB, joining a couple of tables, convert that to XML and send it to another process, tell the user what's going on and whatnot in a single pair of .aspx and .aspx.cs files, using a text editor and the command line compiler - not radically different from any web development platform...

I would agree that there's a lot more room for abuse on the cost front in .NET, but it doesn't have to be that way.

Later,

Will