Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3805670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:42:53+00:00 2026-05-19T14:42:53+00:00

I’m using ASP.NET MVC2 and C#, but this question applies to ASP.NET in general.

  • 0

I’m using ASP.NET MVC2 and C#, but this question applies to ASP.NET in general.

This breaks:

<body id="<asp:ContentPlaceHolder ID="BodyID' runat="server" />">

Intellisense underlines the body tag and the opening quote immediately after id=, and complains:

Validation (HTML 4.01): Element ‘body’ is missing the ‘>’ character from its start tag.

The asp element is ignored, and the id attribute is empty in the rendered HTML. (Same problem whether I use double or single quotes inside the ASP element, tho the latter breaks syntax hilighting in VS.)

This works (assuming I set the session variable):

<body id="<%: Session["BodyID"] %>">

Why is it that inline evaluation is supported inside HTML attributes, but ASP controls won’t render inside attributes?

Here’s my use case: based on data passed from the controller, the view knows what type of data it’s rendering. The view injects data into various places in the master page. I can inject a title into the head, and markup into the body — but I also want to inject data into some attributres. IDs and class names are the obvious examples, but there are others.

I want to do this while still maintaining valid markup; no tricks like dynamically rendering the entire body tag — I want a page that looks like a valid HTML or XML doc at all times in Visual Studio.

Using inline eval is OK, but it requires me to set properties, which I do in the model or controller. In some cases that’s necessary, but in others the values are static — I have a view that’s purpose-built, and I just need to inject a static value from the view into the master page. I don’t want to go thru all the overhead of creating an abstract controller class, having all my controllers inherit from it, etc. just to get to the same functionality I already have when I’m injecting markup.

Side question (yes, I should open a separate question for it): What’s the order of evaluation of ASP controls and inline code nuggets? I assume the code nuggets are resolved first, before the ASP controls, so I could e.g. put a code nugget inside an ASP control declaration. But I can’t find docs that detail the process — can anyone point them out to me?

Thanks!

UPDATE: Pauli mentioned that you can indeed use ContentPlaceholders anywhere you like, as long as they’re not inside an element that’s already marked runat="server". I tested again, and see he’s correct — I missed that initially. Visual Studio is still confused and gives an HTML validation warning, but the expected value appears in the attribute when the page is rendered. So, the answer to the question is “But you can!”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:42:54+00:00Added an answer on May 19, 2026 at 2:42 pm
    1. you shouldn’t use WebForms controls with MVC
    2. use ” around your ID and runat, since the parser is confused of all your conflicting “‘s

    Since the body tag doesn’t have runat=”server” its not treated as a server control, but just clear text and you can therefor put a contentplaceholder, or whatever other control wherever you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.