2009-10-27 2 views
0

나는 ErrorNotificationBox라는 사용자 지정 사용자 제어 할 수 있습니다.Html 헬퍼 확장 - 사용자 Conrol

<%@ Register Src="~/PathTo/ErrorNotificationBox.ascx" TagName="ErrorNotificationBox" TagPrefix="uc" %> 

<uc:ErrorNotificationBox Runat="server" id="myEnb" Caption="My Test Caption" /> 

내 사용자 정의 컨트롤을 포함하는 Html 헬퍼를 확장 할 수 있나요 ... 내가 옛날을 내 페이지에 그를 걸려면? 예 ...

<%= Html.ErrorNotificationBox("My Test Caption")%> 

도움을 주셔서 감사합니다. HTML 헬퍼의 대부분의 메소드

답변

1

ETFairfax는 확장 방법이다. 당신은 쉽게 자신을 추가 할 수 있습니다.

public static class MyExtensions 
{ 
    public static string ErrorNotificationBox(this HtmlHelper helper, string caption) 
    { 
     //generate and return the html for your error box here. 
     // loading and returning an instance of a user control (.ascx) 
     // as a string is difficult. You may find it easier to 
     // create the html with a string builder. 
    } 
} 
관련 문제