web 2.0

ASP.NET(vb.net) & Web User Control

ASP.NET(vb.net) & Web User Control - Web User Control : Web user controls are controls that you can define as you need them for your applications, using the same programming techniques that you use to write Web Forms pages. You can create Web user controls when you need to create reusable pieces of UI that will be used throughout your application. A user control can contain HTML, server controls, and event-handling logic. Like a compiled control, it can expose properties that the host Web Forms page can set.

ShotDev Focus:
- ASP.NET(vb.net) & Web User Control

Example 1

MyUserControl.ascx (Web User Control)

<script Language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'*** Code ***'
Me.lblText.Text = "ShotDev.Com Banner"
End Sub
</script>
<table style="width: 495px" border="1">
<tr>
<td style="height: 73px; text-align: center">
<asp:Label ID="lblText" runat="server" Font-Size="X-Large"></asp:Label></td>
</tr>
</table>

MyWebPage.aspx (Web Form)

<%@ Register Src="MyUserControl.ascx" TagName="MyUserControl" TagPrefix="uc1" %>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'*** Code ***'
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<uc1:MyUserControl id="MyUsrCtrl" runat="server" />
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) & Web User Control
.
.
Example 2 (Code Behind)

MyUserControl1.ascx (Web User Control)

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MyUserControl1.ascx.vb" Inherits="MyUserControl1" %>
<table style="width: 495px" border="1">
<tr>
<td style="height: 73px; text-align: center">
<asp:Label ID="lblText" runat="server" Font-Size="X-Large" Text="ShotDev.Com Banner"></asp:Label></td>
</tr>
</table>

MyUserControl1.ascx.vb (Web User Control)

Public Class MyUserControl1
Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

End Class

MyWebPage1.aspx (Web Form)

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyWebPage1.aspx.vb" Inherits="MyWebPage1" %>
<%@ Register Src="MyUserControl1.ascx" TagName="MyUserControl1" TagPrefix="uc1" %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<uc1:MyUserControl1 id="MyUsrCtrl1" runat="server" />
</form>
</body>
</html>

MyWebPage1.aspx.vb (Web Form)

Public Class MyWebPage1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

End Class

Screenshot

ASP.NET(vb.net) & Web User Control
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.