web 2.0

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

ASP.NET(vb.net) & Web User Control and Property - Web User Control : How to use web user controls and send and receive property web form between web user control.

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

Example 1

MyUserControl2.ascx (Web User Control)

<script Language="VB" runat="server">
Public strText As String
Sub Page_Load(sender As Object, e As EventArgs)
Me.lblText.Text = strText
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>

MyWebPage2.aspx (Web Form)

<%@ Register Src="MyUserControl2.ascx" TagName="MyUserControl2" TagPrefix="uc1" %>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'*** Code ***'
Me.MyUsrCtrl.strText = "Welcome To www.ShotDev.Com"
End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<uc1:MyUserControl2 id="MyUsrCtrl" runat="server" />
</form>
</body>
</html>

Screenshot

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

MyUserControl3.ascx (Web User Control)

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MyUserControl3.ascx.vb" Inherits="MyUserControl3" %>
<table style="width: 495px" border="1">
<tr>
<td style="height: 73px; text-align: center">
<asp:Label ID="lblText1" runat="server" Font-Size="X-Large"></asp:Label><br />
<asp:Label ID="lblText2" runat="server" Font-Size="X-Large"></asp:Label><br />
<asp:Label ID="lblText3" runat="server" Font-Size="X-Large"></asp:Label>
</td>
</tr>
</table>

MyUserControl3.ascx.vb (Web User Control)

Public Class MyUserControl3
Inherits System.Web.UI.UserControl

Public strText1 As String
Public strText2 As String
Public strText3 As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.lblText1.Text = strText1
Me.lblText2.Text = strText2
Me.lblText3.Text = strText3
End Sub

End Class

MyWebPage3.aspx (Web Form)

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

MyWebPage3.aspx.vb (Web Form)

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

Screenshot

ASP.NET(vb.net) & Web User Control & Property
.
.
.
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.