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

  • Home
  • SEARCH
  • 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 508659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:55:48+00:00 2026-05-13T06:55:48+00:00

In an Asp.net MVC application I’d like to encapsulate the ugly wrapper code (just

  • 0

In an Asp.net MVC application I’d like to encapsulate the ugly wrapper code (just a literal html opening string and another closing string) we use to make corners and shadows compatible with older browsers (we don’t use javascript for performance reasons) in a manner compatible with the visual studio design view.

I’d like to put the wrapper divs in a control so that I can use them in a .aspx view page and not have to look at all the mess required to make fancy corners & shadows but still get the benefit of seeing the results in the designer.

//open wrapper literal
actual content
//close wrapper literal

I couldn’t figure out how to inject content inside 1 control and have the results visible in the designer the way master pages do, so I’m testing a system using 2 controls containing the literal html.

example usage – with one control opening and another closing

<ShadowBoxStart /> //contains div open tags
Hello World. This is actual content with all the nice style divs wrapped around
<ShadowBoxEnd /> //contains div close tags

This renders properly in all browsers when I run the application but the designer seems to be confused by the fact that one control opens the divs and another closes them and renders junk. The System.Web.Mvc.ViewUserControls I’m using contain nothing but literal html, and I’ve replicated the behavior with several different standard style & div configurations so I’m stumped as to what is confusing the designer.

I’d like to keep the solution really simple because this is mainly a convenience setup and not worth a lot of added complexity. Any ideas?

  • 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-13T06:55:49+00:00Added an answer on May 13, 2026 at 6:55 am

    Have you thought of creating an HtmlHelper extension a la the BeginForm extension that would allow you to do the single open/close tags. This extension returns an object of a class that implements IDisposable and uses the Dispose method to generate the closing tag.

    Then your HTML would look like:

    <% using (Html.ShadowBoxStart()) { %>
       Hello, World!
    <% } %>
    

    Some code that you might be able adapt:

    public static class HtmlHelperExtensions
    {
        /// <summary>
        /// Begins a container block using the specified tag.  Writes directly to the response.  Expected to be used within a using block.
        /// </summary>
        /// <param name="helper">HtmlHelper object from a View.</param>
        /// <param name="tag">The container tag (div, span, hN, etc.)</param>
        /// <returns>An MvcContainer that writes the closing tag when it is disposed.</returns>
        public static MvcContainer BeginContainer( this HtmlHelper helper, string tag )
        {
            return BeginContainer( helper, tag, null );
        }
    
        /// <summary>
        /// Begins a container block using the specified tag.  Writes directly to the response.  Expected to be used within a using block.
        /// </summary>
        /// <param name="helper">HtmlHelper object from a View.</param>
        /// <param name="tag">The container tag (div, span, hN, etc.)</param>
        /// <param name="htmlAttributes">HTML attribute to apply to the tag.</param>
         /// <returns>An MvcContainer that writes the closing tag when it is disposed.</returns>
        public static MvcContainer BeginContainer( this HtmlHelper helper, string tag, object htmlAttributes )
        {
            var builder = new TagBuilder( tag );
            builder.MergeAttributes( new ParameterDictionary( htmlAttributes ) );
            helper.ViewContext.HttpContext.Response.Write( builder.ToString( TagRenderMode.StartTag ) );
            return new MvcContainer( helper.ViewContext.HttpContext.Response, tag );
        }
    }
    

    Container class:

    /// <summary>
    /// Used by the HtmlHelpeExtensions in conjunction with a using block to close
    /// a container tag.
    /// </summary>
    public class MvcContainer : IDisposable
    {
        protected bool Disposed { get; set; }
        protected HttpResponseBase HttpResponse { get; set; }
        protected string Tag { get; set; }
    
        public MvcContainer( HttpResponseBase httpResponse, string tag )
        {
            if (httpResponse == null)
            {
                throw new ArgumentNullException( "httpResponse" );
            }
    
            if (string.IsNullOrEmpty( tag ))
            {
                throw new ArgumentNullException( "tag" );
            }
    
            this.HttpResponse = httpResponse;
            this.Tag = tag;
        }
    
        /// <summary>
        /// Write the closing tag
        /// </summary>
        public virtual void EndContainer()
        {
            this.Dispose( true );
        }
    
        #region IDisposable Members
    
        /// <summary>
        /// Write the closing tag
        /// </summary>
        public void Dispose()
        {
            this.Dispose( true );
            GC.SuppressFinalize( this );
        }
    
        protected virtual void Dispose( bool disposing )
        {
            if (!this.Disposed)
            {
                this.Disposed = true;
                this.HttpResponse.Write( string.Format( "</{0}>", this.Tag ) );
            }
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 286k
  • Answers 286k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to access members via this, it's a… May 13, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer It's a bad practice, in general, because it defeats the… May 13, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer countries.sort_by do |country| medals = country.gold + country.silver + country.bronze… May 13, 2026 at 4:55 pm

Related Questions

I am using JW Player in an ASP.NET MVC application and I'm trying to
I'm checking out Linq for NHibernate 2.1 to use in an ASP.NET MVC application
I have an ASP.Net/MVC application and I'm trying to send HTML emails. I'm doing
What is the best Image Manager to integrate in TinyMce editor apart the official
In an ASP.NET MVC application during application_start a new thread gets startet. The thread

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.