asp.netcontrolsservercontrols

is it strange to generate controls into placeholders to avoid the "ugly" long Control ClientID's?


More and more I dislike this long ID's by server controls...

But the other method to generate it in codebehind I think is not the sense of the easy thing of asp.net, is it?

So would you prefer that method by yourself? I'm going to create medium and big projects next year in company, thats the reason why I ask. Me self come from PHP and while remembering by a clean sourcecode i'm going to be sick :)

I use asp.net webforms in fact of the easy developing cool solutions in short time. I'm not sure after some impressions of MVC that's also possible in this way.


Solution

  • Generally you would not want to generate your controls in the CodeBehind since it makes visual layout a bit more difficult. There are a few things to keep in mind, though.

    First, it isn't difficult to create controls in the CodeBehind but there are costs to it that go beyond just the UI layout. That is, the cost comes later when you revisit a page and have to figure out what comes from where. Doing things in the CodeBehind can trip you up if you aren't careful.

    Second, if you can stay flexible enough to jump to ASP.NET 4.0 then your frustrations will be short-lived as 4.0 gives you a way to define your client-side IDs.

    Third, MVC is an alternative but I'd be hesitant to go that way unless you are really just starting. There are significant drawbacks to MVC in terms of productivity for people used to WebForms development. I discuss this at some length here.

    Right now, you have to deal with complex IDs if and when you need to reference a control from Javascript/JQuery. This is a relatively circumscribed problem in most situations and, again, will go away as soon as you move to 4.0. MVC, however, is a big commitment: a different way of thinking and one that removes some very productive tools from your tool-belt if you are used to WebForms development. The primary reason to adopt it - the addition of other tools such as easy JQuery integration - is also undercut by changes in .NET 4. In the end, it isn't really a decision about which is "best" so much as a decision about which fits your style of development and sensibilities.

    Good luck!

    P.S.: You do know that you can get .NET 4/Visual Studio 2010 now, right? It is fully ready for deployable projects and represents are significant step up from VS 2008.