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 113453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:42:17+00:00 2026-05-11T02:42:17+00:00

Some texts on ASP.NET MVC state that there are no runat server tags, even

  • 0

Some texts on ASP.NET MVC state that ‘there are no runat server tags’, even this MSDN article says this, when, right above that statement there is a code example with a runat server tag in the HEAD element:

  • http://msdn.microsoft.com/en-us/magazine/cc337884.aspx

And on StackOverflow conversations I read

‘The fact that you want to use ‘runat=server’ controls means that you should be doing a traditional ASP.NET app.

And of course in the Site.Master page there are runat server attributes in the ContentPlaceHolders.

The only thing I see absent from ASP.NET MVC in terms of runat server is the ubiquitous FORM runat=’server’ tag on each .aspx page/view.

But what about the rest of the runat server tags in ASP.NET MVC, what do people mean when they say that ASP.NET MVC does not have these?

  • 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. 2026-05-11T02:42:18+00:00Added an answer on May 11, 2026 at 2:42 am

    If you use a runat=’server’ tag on ANY element, such as a DIV it will render that code as a separate method in the compiled page.

    If you’re converting ‘legacy’ code its a good idea to remove all runat tags right up front otherwise you end up in a situation where code like the following gives you an error.

    <% foreach (var cat in cats) { %>     <div runat='server'>          <span class='name'> <%= cat.name %> </span> is a          <span class='breed'> <%= cat.breed %> </span>     </div>  <% } %> 

    This code will fail telling you some craziness about 'cat' being out of scope. Eventually when you look at the full generated code you’ll see that the <div> has been generated as its whole own method – which is of course a different scope with no cats in sight.

    Back for a second to the default template for an MVC application:

    You’ll see the current template gives you this for the head :

    <head runat='server'>     <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />     <title><%= Html.Encode(ViewData['Title']) %></title>     <link href='../../Content/Site.css' rel='stylesheet' type='text/css' /> </head> 

    This left me wondering — if we’re using <%= syntax to write the title directly into the title tag – then why would we need to make it runat?

    It turns out as I suspected that the codebehind for head looks for an existing value inside the title tag (which would have been output here by <%= Html.Encode(ViewData['Title']) %>. If it finds one (which will be the case for the all sample views in the MVC template) then it won’t do anything further. If no title exists (if ViewData[‘Title’] is null or empty) it will default to whatever is defined in your view by the Title attribute :

    <%@ Page Language='C#' MasterPageFile='~/Views/Shared/RRMaster.Master'  Title='View Products' AutoEventWireup='true' CodeBehind='ViewProduct.aspx.cs' Inherits='RR_MVC.Views.Products.ViewProduct' %> 

    In my master page I would have removed the runat='server' tag – since I dont think I’ll ever want to populate my page title from the view’s Title property. But I’m holding off doing this pending Phil’s promised blog post on the subject – in case the runat server gives me anything useful for my CSS and JS too.

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

Sidebar

Related Questions

Greetings, I have an asp.net mvc application. I have some links that corresponds to
I'm writing some unit tests for an ASP.NET MVC controller that's using SubSonic3 generated
I'm developing a site in asp.net MVC that should generate invoices. After some reading
I'm looking for some kind of text-parser for ASP.NET that can make HTML from
I am using these technologies: SQL Server 2005, ASP.NET MVC, NHibernate/sharp architecture and would
I’m running some performance tests on an ASP.NET MVC application. I see a high
I have some text, stored in a table. I'm using asp.net mvc to display
I have a asp.net mvc web application an it uses some favicon.ico. Now when
I'm working on an ASP.NET MVC 3 application and having some issues. I've got
In ASP.NET MVC, if I have some content on the page I can do

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.