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
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> .
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With