Controls versus standard HTML

后端 未结 11 1397
醉话见心
醉话见心 2020-12-15 09:55

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 asp:-style

相关标签:
11条回答
  • 2020-12-15 10:21

    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, the reason you dont have the tedious HTML crafting is because the ASP.NET controls do it all for you.

    To some extent you can control/tweak these things, even if it means inheriting the control and tweaking the HTML output from there.

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

    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.

    0 讨论(0)
  • 2020-12-15 10:22

    @Brian, Yup! 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 here.

    I would strongly recommend checking them out, has help me no end :)

    0 讨论(0)
  • 2020-12-15 10:24

    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.

    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:

    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

    0 讨论(0)
  • 2020-12-15 10:26

    If you want that much control over the rendered HTML, look into ASP.NET MVC instead.

    0 讨论(0)
  • 2020-12-15 10:29

    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"_

    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.

    Hope this helps

    0 讨论(0)
提交回复
热议问题