HTML helpers in Webform?

最后都变了- 提交于 2019-12-01 18:24:32

问题


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


回答1:


At your solution. Add a special folder ASP.net Folder called code. Then paste your Helpers.cs file at it. Then you can access it.




回答2:


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>


来源:https://stackoverflow.com/questions/15173272/html-helpers-in-webform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!