Reputation: 6353
The code below works but confuses Visual Studio. Are there alternative/better ways to accomplish this?
<body <asp:contentplaceholder id="BodyAttribute" runat="server"/>>
Upvotes: 1
Views: 746
Reputation: 2011
You could always do
<body id="body1" runat="server">
this page shows an example - http://msdn.microsoft.com/en-us/library/zzk7dby1(vs.71).aspx
the example is based off .net 1.1 but i've used something similar for .net 2.0
Upvotes: 1
Reputation: 24118
I don't think doing this is a good idea in general.
First of all, with ContentPlaceHolder
s you can easily end-up with HTML with newlines in id
attribute.
Secondly, the code will be a total spaghetti. You will not be able to maintain it.
Thirdly, there must be a better way of accomplishing what you need.
For example, if you need to change the body id
for the CSS styling purpose, or using it in JavaScript you will be better of with creating a nested div for that.
Master:
<body>
<!-- div wrapper for general styling purposes -->
<div id="mainContentWrapper">
<asp:contentplaceholder id="Maincontent" runat="server" />
</div>
</body>
Page:
<asp:content contentplaceholderid="MainContent" runat="server">
<!-- div wrapper for page specific styling -->
<div id="pageSpecificIdForYourPuprose">
Your content goes here
</div>
</asp:content>
Which will give you very style-able HTML:
<body>
<div id="mainContentWrapper">
<div id="pageSpecificIdForYourPuprose">
Your content goes here
</div>
</div>
</body>
I would really try to avoid those WebForms tricky things to accomplish simple thing. Simple things can be done the simple way (pretty often at least).
Hope that helps.
Upvotes: 1
Reputation: 66649
Other way
<asp:contentplaceholder id="BodyAttribute" runat="server"><body></asp:contentplaceholder>
and on contentPlaceholder you type
<body attr="whatever">
If not place holder found, then the <body>
is used.
Upvotes: 1