Web Application Project Method
- Create a new ASP.Net Web Application. Take note of the name, mine is called WebApplication2. If you already have an existing web application, which is likely, double click the properties section of your project and check the "Assembly Name" property, make note of it.
- Create a new Class in the web applcation named Literal.cs
- Put in code similar to the following for the class defenition:
namespace CustomControls { public class Literal : System.Web.UI.WebControls.Literal { } }
- Add the following register tag to the top of your aspx page
<%@ Register assembly="WebApplication2" namespace="CustomControls" tagprefix="web" %>
- Add the new control to your page:
<web:Literal ID="Literal1" runat="server" Text="test" />
- Create a new Empty Website (ASP.Net).
- Add a new ASP.Net Server Control library named CustomControls to the solution.
- Add a new Class to the new project called Literal (I'm using C# so my file is named Literal.cs). Below is my super basic code, that I believe should match the code described in the question.
namespace CustomControls { public class Literal : System.Web.UI.WebControls.Literal { } }
- Add a reference to the CustomControls project to your website.
- Add the assembly registration to the top of your aspx page:
<%@ Register assembly="CustomControls" namespace="CustomControls" tagprefix="web" %> - Add a new instance of the control to your page:
<web:Literal ID="Literal1" runat="server" Text="test" />
- Create a new Empty Website (ASP.Net).
- Add a new Class to the App_Code folder Literal2 (I'm using C# so my file is named Literal2.cs). Below is my super basic code, that I believe should match the code described in the question. I called it 2 so that you can use this in conjunction with the method described above without getting compile errors
namespace CustomControls { public class Literal2 : System.Web.UI.WebControls.Literal { } }
- Register the assembly/namespace for app_code in your aspx page by adding the following line to the top
<%@ Register Namespace="CustomControls" Assembly="__code" tagprefix="web" %> - Add an instance of the new control to your page:
<web:Literal2 ID="literal2" runat="server" Text="test2" />
From : http://stackoverflow.com/questions/3003343/custom-control-in-asp-net-c-sharp
ไม่มีความคิดเห็น:
แสดงความคิดเห็น