<p>I'm getting into ASP.NET (C# - I know it doesn't matter for this particular question, but full disclosure and all that), and while I love that the <code>asp:</code>-style controls save me a lot of tedious HTML-crafting, I am often frustrated with certain behaviors. I encountered one last night when working with Master Pages: my <code>&lt;asp:BulletedList ID="nav"&gt;</code>, when converted into HTML, became <code>&lt;ul id="ct100_nav"&gt;</code>.</p>

<p>There are other issues--I noticed that when you auto-populate a DataGrid, it adds attributes to the resulting table that I don't necessarily want there.</p>

<p>I know that there is a certain amount of "convention over configuration" that you have to accept when you rely on a framework to take over some of your tedious duties, but the "conventions" in these cases aren't so much any established conventions, but rather unnecessary extras. I know <em>why</em> the ID adds the prefix, but I should be able to tweak and turn things like this off, especially since, as a bit of a web standards evangelist, I don't duplicated HTML id's in a single page anyway.</p>

<p>So the question here is for those ASP.NET devs more seasoned than I: in your experiences in developing and deploying apps, how do you leverage these controls? Do you find yourself resorting back to hard-coded HTML? Do you use a blend? I don't want to design my HTML around idiosyncratic quirks in these controls, but, if possible, I'd like to leverage them when possible. </p>

<p>What's a boy to do?</p>

[{'answer_id': 22089, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 1, 'selected': False, 'text': '<p>I too am on my adventure into ASP.NET and have also had similar frustrations.. However, you soon get used to it. You just need to remember, <strong>the reason you dont have the tedious HTML crafting is because the ASP.NET controls do it all for you</strong>.</p>\n\n<p>To some extent you can control/tweak these things, even if it means inheriting the control and tweaking the HTML output from there.</p>\n\n<p>I have had to do that in the past, where certain controls were not passing W3C validation by default by putting some extra markup here and there, so I simply overrode and edited as necessary (a fix that too literally a couple of minutes)..</p>\n\n<p>I would say learn about how the controls system works.. Then knock a few together yourself, this has really helped me grok whats going on under the hood, so if I ever get any problems, I have an idea where to go.</p>\n'}, {'answer_id': 22096, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 2, 'selected': False, 'text': '<p>As for the ID\'s on server-controls: You can find the actually ID that is going to be written to the browser by accessing ClientID. That way you can combine server-side og client-side scripting and still dont have to hardcode _id="ct100_nav"_ </p>\n\n<p>I always try to use the included controls instead of "hacking" HTML, because if there is an update or some improvement later on, all my code will still work by just replacing the framework and I don\'t have to change any HTML.</p>\n\n<p>Hope this helps</p>\n'}, {'answer_id': 22107, 'author': 'Davide Vosti', 'author_id': 1812, 'author_profile': 'https://Stackoverflow.com/users/1812', 'pm_score': 0, 'selected': False, 'text': "<p>If the ID's prefix added by ASP.NET is an issue for you to access them later using JS or something... you have the .ClientID property server side.</p>\n\n<p>If the overhead added by ASP.NET you should consider ASP.NET MVC (still preview) where you have full control over the emitted html.</p>\n\n<p>I'm moving to MVC because I don't like all that stuffs added too....</p>\n"}, {'answer_id': 22109, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 2, 'selected': False, 'text': '<p>@Brian,\nYup! You can pretty much control all the behaviour.. Consider looking into creating Custom Controls (there are three types). I recently gave an overview of them in my question <a href="https://stackoverflow.com/questions/17532/aspnet-custom-controls-composites">here</a>.</p>\n\n<p>I would <em>strongly</em> recommend checking them out, has help me no end :)</p>\n'}, {'answer_id': 22112, 'author': 'JamesSugrue', 'author_id': 1075, 'author_profile': 'https://Stackoverflow.com/users/1075', 'pm_score': 5, 'selected': True, 'text': '<p>Personally, </p>\n\n<p>I think the standard ASP.NET controls are fine for inhouse stuff - quick and dirty is good in that scenario. But, I once worked with a web developer who was also a designer and he refused to use the ASP.NET controls and only code in HTML and add runat="server" tags when needed. This was more because he wanted to know exactly how his HTML was going to be rendered, and at the time anyway, some of the ASP.NET controls wouldn\'t render to standards compliance.</p>\n\n<p>I sit somewhere in the middle - use HTML where appropriate and not when not. You can sort of best of both worlds with the <a href="http://weblogs.asp.net/scottgu/archive/2006/05/02/444850.aspx" rel="noreferrer">CSS control Adapters</a></p>\n'}, {'answer_id': 22202, 'author': 'Slavo', 'author_id': 1801, 'author_profile': 'https://Stackoverflow.com/users/1801', 'pm_score': 0, 'selected': False, 'text': "<p>I think most of the answers here take a designer's point of view. On a small-to-medium project it might seem like an overhead to synchronize code and CSS/HTML and make them standards-compliant and clean. A designer's way to do that is to have full control over rendered HTML. But there's many ways to have that full control in ASP.NET. And for me, having the required HTML in the aspx/ascx file is the most non-scalable and dirty way to do it. If you want to style controls through CSS, you can always set a class server-side through the CssClass property. If you want to access them through JS, you can emit the JS with right IDs server-side again. The only disadvantage that this provides is that a dev and a designer have to work together closely. On any large project this is unavoidable anyway. But the advantages ASP.NET provides far outnumber these difficulties.\nStill, if you want standards-compliant HTML, skinning support and other goodies to control rendered markup, you can always use thrid-party controls.</p>\n"}, {'answer_id': 22221, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 1, 'selected': False, 'text': '<p>The HTML renders with those sort of IDs because its ASP.NET\'s way of preventing ID collisions.  Each container control, such as a Master page or Wizard control, will prepend an "ID_" on its childrens\' IDs.</p>\n\n<p>In the case of your bullet list, the ListView provides a nice middle ground.  You can still bind it to a datasource, but it gives you much tighter control over the rendered HTML.  Scott Gu has a nice intro to the ListView here:  </p>\n\n<p><a href="http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx</a></p>\n'}, {'answer_id': 380346, 'author': 'Rex Morgan', 'author_id': 46429, 'author_profile': 'https://Stackoverflow.com/users/46429', 'pm_score': 0, 'selected': False, 'text': '<p>As Dave Ward has already mentioned, "it\'s ASP.NET\'s way of preventing ID collisions."</p>\n\n<p>A very good example of this is if you\'re attempting to put a control inside of a custom control, then use that custom control in a repeater, so that custom control\'s HTML would be output multiple times for the page.</p>\n\n<p>As others have mentioned, if you need to access the controls for javascript, use the ClientScript property which will give you access to a ClientScriptManager and register your scripts to the page this way.  Be sure when writing your scripts to use the ClientID property on the control you\'re trying to reference instead of just typing in the control\'s ID.</p>\n'}, {'answer_id': 380368, 'author': 'Jason Kester', 'author_id': 27214, 'author_profile': 'https://Stackoverflow.com/users/27214', 'pm_score': 2, 'selected': False, 'text': "<p>The short answer is that you should never use an asp:... version of a standard HTML control unless you have a really good reason.  </p>\n\n<p>Junior developers often get suckered into using those controls because they're covered in most ASP.NET books, so it's assumed that they must be better.  They're not.  At this point, after 8 years of daily ASP.NET development, I can only think of 2 or 3 cases where it actually makes sense to use an asp:... INPUT control over a standard HTML one.</p>\n"}, {'answer_id': 380466, 'author': 'annakata', 'author_id': 13018, 'author_profile': 'https://Stackoverflow.com/users/13018', 'pm_score': 4, 'selected': False, 'text': '<p>I\'m actually quite relieved to see some opinions here agreeing with my own: ASP.NET as a template language is very poor.</p>\n\n<p>I\'d just like to rebut a couple of the pro points made here (flamesuit on!):</p>\n\n<p>Dave Ward mentions ID collisions - this is true, but my how badly handled. I would have preferred to see nodes referenced by xpath or deep css selectors than by making the ID  effectively useless except by deferring to ASP.NET internals like clientID - it just makes writing CSS and JS that much harder pointlessly.</p>\n\n<p>Rob Cooper talks about how the controls are a replacement for HTML so it\'s all fine (paraphrasing, forgive me Rob) - well it\'s not fine, because they took an existing and well understood language and said "no, you have to do things our way now", and their way is <em>very</em> poorly implemented. e.g. asp:panel renders a table in one browser and a div in another! Without documentation or execution, the markup for a login control (and many others) isn\'t predictable. How are you going to get a designer to write CSS against that?</p>\n\n<p>Espo writes about how controls give you the benefits of abstraction if the platform changes the html - well this is clearly circular (It\'s only changing because the platform is changing, and wouldn\'t need to if I just had my own HTML there instead) and actually creates a problem. If the control is going to change with updates again how is my CSS supposed to cope with that?</p>\n\n<p>Apologists will say "yes but you can change this in the config" or talk about overriding controls and custom controls. Well why should I have to? The css friendly controls package meant to fix some of these problems is anything but with it\'s unsemantic markup and it doesn\'t address the ID issue.</p>\n\n<p>It\'s impossible to implement MVC (the abstract concept, not the 3.5 implementation) out of the box with webform apps becuase these controls so tightly bind the view and control. There\'s a barrier of entry for the traditional web designer now because he has to get involved with server side code to implement what used to be the separate domains of CSS and JS. I sympathise with these people.</p>\n\n<p>I do strongly agree with Kiwi\'s point that controls allow for some very rapid development for apps of a certain profile, and I accept that for whatever reason some programmers find HTML unpleasant, and further that the advantages the other parts of ASP.NET give you, which requires these controls, <em>may</em> be worth the price.</p>\n\n<p>However, <em>I</em> resent the loss of control, I feel the model of dealing with things like classes, styles and scripting on the codebehind is a wrongheaded step backwards, and I further feel that there are better models for templating (implementation of microformats and xslt for this platform) although replacing controls with these is non-trivial.</p>\n\n<p>I think ASP.NET could learn a lot from related tech in LAMP and rails world, until then I hope to work with 3.5 MVC where I can.</p>\n\n<p>(sorry that was so long &lt;/rant&gt;)</p>\n'}, {'answer_id': 1179975, 'author': 'Babak Naffas', 'author_id': 120753, 'author_profile': 'https://Stackoverflow.com/users/120753', 'pm_score': 0, 'selected': False, 'text': '<p>If you want that much control over the rendered HTML, look into <a href="http://www.asp.net/mvc/" rel="nofollow noreferrer">ASP.NET MVC</a> instead.</p>\n'}]
['https://Stackoverflow.com/questions/22084', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1344/']