Subscribe

RSS Feed (xml)

Declaring a User Control in ASP.NET

Simply place the appropriate code inside of an .ASCX file.The ASCX page:
<%@ Control Language=”VB” %>
<asp:label runat=”server” id=”lblSample” />
In <script runat=”server” /> block or codebehind:
Sub Page_Load(sender as object, e as EventArgs)
lblSample.Text = “Sample Control Text”
End Sub

User Controls are declared almost the same as normal Web Forms, except that they have
the .ASCX extension and use @ Control directives instead of @ Page directives. Like
the @ Page directive, the @ Control directive supports several parameters, all of which
are optional. It is generally best not to include a server-side form tag in a User Control
(for example, <form runat=”server”>), because there can be only one of these per Web
Form.Also, User Controls that include form controls must be placed within a server-side
form for these controls to work correctly. Also, codebehind classes for User Controls
need to inherit from System.Web.UI.UserControl.

No comments:

Archives

Variety in the Web World