views:

55

answers:

4

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 :)

EDIT: After some answers: 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.

Best regards

+2  A: 

I have the exact same feeling as you, but I choose to live with the ugly IDs.

There are two good options though.

  • ASP.NET MVC

  • And wait for ASP.NET 4.0. You can put on an option that will give you full control over what will be printed out in the browser.

Eibx
+1  A: 

This is one of the biggest reasons to switch from ASP.NET Webforms to ASP.NET MVC. There's not much you can do with WebForms to alleviate this problem which wouldn't be considered a hack (and I certainly have hacked it in places for just this reason).

Dave Markle
Ok, Thank you, so it seems today is the day i'm going to try again MVC.... whats about my strange alterative I ask :)?
snarebold
+1  A: 

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.

Mark Brittingham
Thank you for your explanation. So I try VS 10 and .net 4 next time.
snarebold
A: 

I stumbled upon this, and I figured that it might be relevant to this.

http://www.west-wind.com/WebLog/posts/4605.aspx

It overrides both UniqueID and ClientID to ID, which is much more clean.

public override string UniqueID
{
    get
    {
        return this.ID;
    }
}

public override string ClientID
{
    get
    {
        return this.ID;
    }
}
Eibx