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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:06+00:00 2026-05-26T15:14:06+00:00

I have an ASP.NET WebForms control (derived from Control, not WebControl, if it helps)

  • 0

I have an ASP.NET WebForms control (derived from Control, not WebControl, if it helps) that has a rather complicated Render() function. The control has no viewstate and only uses the Control approach so it can render output directly. I feel it’s a fine candidate for working with the MVC approach.

I’d like to use it in an MVC application I’m using, however I don’t know what’s the best way to go about it.

At first I thought about converting it to a HTML Helper method, but my control renders a large amount of HTML so the Helper method (with it returning strings) isn’t too attractive.

The alternative is a PartialView, but those are UserControl derivatives, which wouldn’t be appropriate in this case.


I see other HTML Helper methods don’t return HtmlString, but actually use HtmlHelper.ViewContext.Writer to write output directly, but according to this question ( HtmlHelper using ViewContext.Writer not rendering correctly ) he was getting strange results. I’d like to avoid that mishap.


EDIT:

I think I’ve solved it using the HtmlHelper.ViewContext.Writer approach, and I haven’t experienced the same problem as the problem I quoted.

Here’s the code I wrote:

public static class MiniViewHelper {

    public static void RenderMiniView<TModel>(this HtmlHelper html, MiniView<TModel> view, TModel model) {

        TextWriter wtr = html.ViewContext.Writer;
        HtmlTextWriter hwtr = wtr as HtmlTextWriter;
        if( hwtr == null ) hwtr = new HtmlTextWriter( wtr );

        view.Render( hwtr );
    }

}

public abstract class MiniView<TModel> {

    public TModel Model { get; set; }

    public abstract void Render(HtmlTextWriter wtr);

}

public class VeryComplicatedMiniView : MiniView<ComplicatedViewModel> {

    public override void Render(HtmlTextWriter wtr) {

        wtr.WriteLine("VeryComplicatedMiniView ");
    }

}

Used like so from my pages:

<% Html.RenderMiniView( new VeryComplicatedMiniView () { Propery1 = foo }, Model.RelevantMiniViewModel ); %>

Any thoughts?

  • 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-26T15:14:07+00:00Added an answer on May 26, 2026 at 3:14 pm

    The two approaches you have outlined in your question are correct. You could either try to write a custom HTML helper which will spit the same HTML as the control or use a partial.

    I see other HTML Helper methods don’t return HtmlString, but actually
    use HtmlHelper.ViewContext.Writer to write output directly

    ViewContext.Writer should be fine. Returning an IHtmlString from the helper is also fine. Just make sure you are properly encoding it inside since IHtmlString will not be automatically HTML encoded in Razor and it supposes that the helper takes care of this. Using a TagBuilder to generate a DOM tree in a helper is a good approach.

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

Sidebar

Related Questions

I have a ASP.NET webform that, aside from other controls, has a textbox for
I have an ObjectDataSource on an ASP.NET WebForms page, that also has a data-bound
I have an ASP.NET webforms application with a Menu control. How does one hide
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
We have an ASP.NET 2.0 WebForms app that uses MS Ajax 1.0. It's working
I have an ASP.NET Webforms site that is regularly having features added. The majority
I have an ASP.NET 3.5 webforms project written in VB that involves a multi-table
I have a reporting module in an ASP.NET webforms app (C#) that uses dynamic
That's a simple task in ASP.NET WebForms:If you want to show/hide a control all
One of our ASP.NET WebForms 3.5 pages just suddenly decided not to render the

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.