Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML helpers in Webform?

I have a old site that I want to use something like HTML helpers to generate special HTML(in this case complexed buttons). I know how this works in ASP.NET MVC but how can I do it in Webform(not Razor).

I have read suggestions on static methods like this :

public class Helpers
{
    public static string Label1(string target, string text)
    {
        return String.Format("<label for= '{0}'>{1}</label>", target, text);
    }
}

But how is this used in the Webform?

BestRegards

like image 367
Ivy Avatar asked Mar 02 '13 10:03

Ivy


People also ask

How do you create an HTML helper?

The easiest way to create a new HTML Helper is to create a static method that returns a string. Imagine, for example, that you decide to create a new HTML Helper that renders an HTML <label> tag. You can use the class in Listing 2 to render a <label> .

Where do we use HTML helpers?

Strongly Typed HTML Helpers These helpers are used to render the most common types of HTML elements in strongly typed view like as HTML text boxes, checkboxes etc. The HTML elements are created based on model properties.

What is the use of HTML helpers in MVC?

HTML Helpers are used in View to render HTML content. It is not mandatory to use HTML Helper classes for building an ASP.NET MVC application. We can build an ASP.NET MVC application without using them, but HTML Helpers helps in the rapid development of a view.


1 Answers

Put Helpers.cs in your App_Code folder then you can call it like so from your aspx file:

<div class="example>
    <%= Helpers.Label1("some", "text") %>
</div>
like image 85
dav_i Avatar answered Oct 12 '22 01:10

dav_i