Get value from asp.net page control (VB.net) : Introduction « Custom Controls « ASP.NET Tutorial






File: index.aspx

<%@ Page Language="VB" %>
<%@ Register TagPrefix="Java2sASP" TagName="LoginForm" src="Control.ascx" %>

<script runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      lblMessage.Text = "Properties of the user control: " & _
         "<br>id: " & LoginForm1.id & "<br>" & _
         "BackColor: " & LoginForm1.BackColor & "<br>" & _
         "Username: " & LoginForm1.Username & "<br>" & _
         "Password: " & LoginForm1.Password
   end sub
</script>

<html><body>
   <form runat="server">
      <Java2sASP:LoginForm id="LoginForm1" runat="server" 
         Password="MyPassword"
         Username="Chris"
         BackColor="Beige" />
   </form>
   
   <asp:Label id="lblMessage" runat="server" />
</body></html>

File: Control.ascx

<script language="VB" runat="server">
   public BackColor as String = "White"
   public property UserName as string
      Get
         UserName = User.Text
      End Get
      Set
         User.Text = value
      End Set
   end property

   public property Password as string
      Get
         Password = Pass.Text
      End Get
      Set
         Pass.Text = value
      End Set
   end property
   
   public sub Submit(obj as object, e as eventargs)
      lblMessage.Text = "Username: <b>" & User.Text & _
         "</b><br>" & "Password: <b>" & Pass.Text & "</b>"
   end sub
</script>

<table style="background-color:white;font: 10pt verdana;border-width:1;border-style:solid;border-color:black;" 
   cellspacing=15>
   <tr>
      <td><b>Login: </b></td>
      <td><ASP:TextBox id="User" runat="server"/></td>
   </tr>
   <tr>
      <td><b>Password: </b></td>
      <td><ASP:TextBox id="Pass" TextMode="Password" 
             runat="server"/></td>
   </tr>
   <tr>
      <td></td>
      <td><ASP:Button Text="Submit" runat="server" 
             OnClick="Submit" /></td>
   </tr>
</table>

<ASP:Label id="lblMessage" runat="server"/>








14.1.Introduction
14.1.1.Differences between user controls and web pages
14.1.2.Page control with full qualified name(C#)
14.1.3.Get value from asp.net page control (VB.net)
14.1.4.Use properties defined in custom control
14.1.5.Page component with code behind (VB.net)
14.1.6.Exposing Properties from a User Control
14.1.7.Set the properties from user control programmatically.