Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   can't see properties on user control from aspx.vb (http://www.velocityreviews.com/forums/t114338-cant-see-properties-on-user-control-from-aspx-vb.html)

mharness 11-25-2005 08:12 PM

can't see properties on user control from aspx.vb
 
Hello,

I've tried a number of examples showing how to read the properties of a user
control from an aspx file where the code is on the html view of the form but
I can't figure out how to read them from the aspx.vb. Can anyone tell me
how to declare the user control in the aspx.vb file so that I can read the
properties?

I did add "Protected WithEvents UC1 As System.Web.UI.UserControl" to the
component code behind form but that's the only change I have made.

Many thanks,

Mike

Here's the example from dotnetjunkies I've been working with:

UCSub.aspc:

<%@ Control Language="vb" AutoEventWireup="false" Src="UCSub.ascx.vb"
Inherits="UCSub" %>
<div align="center">
<table style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; FONT: 10pt
verdana; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid"
cellspacing="10">
<tr>
<td>
<asp:Label id="lblUserName" runat="server" Font-Bold="true" Text="User
Name:" />
</td>
<td>
<asp:TextBox id="txtUserName" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label id="lblPassword" Font-Bold="True" Text="Password:"
runat="server" />
</td>
<td>
<asp:TextBox id="txtPassword" TextMode="Password" runat="server" />
</td>
</tr>
</table>
</div>

UCSub.ascx.vb..

Public Class UCSub
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblUserName As System.Web.UI.WebControls.Label
Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
Protected WithEvents lblPassword As System.Web.UI.WebControls.Label
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub ClearText()
txtUserName.Text = ""
txtPassword.Text = ""
End Sub

End Class

UCSub.aspx..

<%@ Register TagPrefix="DNJ" TagName="LoginControl" Src="UCSub.ascx" %>
<%@ Page Language="vb" %>
<HTML>
<HEAD>
<title>Using a Sub routine in a UserControl</title>
<script runat="server">
Sub btnSubmit_Click(Sender As Object, e As EventArgs)

End Sub

Sub btnClearText_Click(sender As Object, e As EventArgs)
UC1.ClearText()
End Sub
</script>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="form1" runat="server">
<p></p>
<DNJ:LoginControl id="UC1" runat="server" />
<BR>
<div align="center">
<asp:Button id="btnSubmit" text="Submit" onclick="BtnSubmit_Click"
runat="server" />
<asp:Button id="btnClearText" text="Clear Text"
OnClick="btnClearText_Click" runat="server" />
<p></p>
<asp:label id="lblMessage" runat="server" />
</div>
</form>
</body>
</HTML>

UCSub.aspx.vb..

Public Class UCSub1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Protected WithEvents btnClearText As System.Web.UI.WebControls.Button
Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents UC1 As System.Web.UI.UserControl

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

End Class





mharness 11-28-2005 10:48 AM

Re: can't see properties on user control from aspx.vb
 
Got it.

Created a namespace around the user control class then added imports
[solution name].[namespace] and public [user control ID] as [user
control].ascx.vb to the aspx.vb. After declaring a public property with a
get end get in the ascx.vb I could refer to [user control ID].[property] in
the aspx.vb.

I found good information and the essence of this approach in examples at
http://www.dotnetjohn.com/articles.aspx?articleid=52 and
http://msdn.microsoft.com/library/de...properties.asp .

Mike

"mharness" <bogus@hotmail.com> wrote in message
news:e_6dnegwLqEc4xreRVn-tw@comcast.com...
> Hello,
>
> I've tried a number of examples showing how to read the properties of a
> user control from an aspx file where the code is on the html view of the
> form but I can't figure out how to read them from the aspx.vb. Can anyone
> tell me how to declare the user control in the aspx.vb file so that I can
> read the properties?
>
> I did add "Protected WithEvents UC1 As System.Web.UI.UserControl" to the
> component code behind form but that's the only change I have made.
>
> Many thanks,
>
> Mike
>
> Here's the example from dotnetjunkies I've been working with:
>
> UCSub.aspc:
>
> <%@ Control Language="vb" AutoEventWireup="false" Src="UCSub.ascx.vb"
> Inherits="UCSub" %>
> <div align="center">
> <table style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; FONT: 10pt
> verdana; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid"
> cellspacing="10">
> <tr>
> <td>
> <asp:Label id="lblUserName" runat="server" Font-Bold="true" Text="User
> Name:" />
> </td>
> <td>
> <asp:TextBox id="txtUserName" runat="server" />
> </td>
> </tr>
> <tr>
> <td>
> <asp:Label id="lblPassword" Font-Bold="True" Text="Password:"
> runat="server" />
> </td>
> <td>
> <asp:TextBox id="txtPassword" TextMode="Password" runat="server" />
> </td>
> </tr>
> </table>
> </div>
>
> UCSub.ascx.vb..
>
> Public Class UCSub
> Inherits System.Web.UI.UserControl
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
> Protected WithEvents lblUserName As System.Web.UI.WebControls.Label
> Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
> Protected WithEvents lblPassword As System.Web.UI.WebControls.Label
> Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
>
> 'NOTE: The following placeholder declaration is required by the Web
> Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> Public Sub ClearText()
> txtUserName.Text = ""
> txtPassword.Text = ""
> End Sub
>
> End Class
>
> UCSub.aspx..
>
> <%@ Register TagPrefix="DNJ" TagName="LoginControl" Src="UCSub.ascx" %>
> <%@ Page Language="vb" %>
> <HTML>
> <HEAD>
> <title>Using a Sub routine in a UserControl</title>
> <script runat="server">
> Sub btnSubmit_Click(Sender As Object, e As EventArgs)
>
> End Sub
>
> Sub btnClearText_Click(sender As Object, e As EventArgs)
> UC1.ClearText()
> End Sub
> </script>
> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body>
> <form id="form1" runat="server">
> <p></p>
> <DNJ:LoginControl id="UC1" runat="server" />
> <BR>
> <div align="center">
> <asp:Button id="btnSubmit" text="Submit" onclick="BtnSubmit_Click"
> runat="server" />
> <asp:Button id="btnClearText" text="Clear Text"
> OnClick="btnClearText_Click" runat="server" />
> <p></p>
> <asp:label id="lblMessage" runat="server" />
> </div>
> </form>
> </body>
> </HTML>
>
> UCSub.aspx.vb..
>
> Public Class UCSub1
> Inherits System.Web.UI.Page
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
> Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
> Protected WithEvents btnClearText As System.Web.UI.WebControls.Button
> Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> Protected WithEvents UC1 As System.Web.UI.UserControl
>
> 'NOTE: The following placeholder declaration is required by the Web
> Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> End Class
>
>
>
>




mharness 12-04-2005 02:43 PM

Re: can't see properties on user control from aspx.vb
 
Got it.

Created a namespace around the user control class then added imports
[solution name].[namespace] and public [user control ID] as [user
control].ascx.vb to the aspx.vb. After declaring a public property with a
get end get in the ascx.vb I could refer to [user control ID].[property] in
the aspx.vb.

I found good information and the essence of this approach in examples at
http://www.dotnetjohn.com/articles.aspx?articleid=52 and
http://msdn.microsoft.com/library/de...properties.asp .

Mike

"mharness" <bogus@hotmail.com> wrote in message
news:e_6dnegwLqEc4xreRVn-tw@comcast.com...
> Hello,
>
> I've tried a number of examples showing how to read the properties of a
> user control from an aspx file where the code is on the html view of the
> form but I can't figure out how to read them from the aspx.vb. Can anyone
> tell me how to declare the user control in the aspx.vb file so that I can
> read the properties?
>
> I did add "Protected WithEvents UC1 As System.Web.UI.UserControl" to the
> component code behind form but that's the only change I have made.
>
> Many thanks,
>
> Mike
>
> Here's the example from dotnetjunkies I've been working with:
>
> UCSub.aspc:
>
> <%@ Control Language="vb" AutoEventWireup="false" Src="UCSub.ascx.vb"
> Inherits="UCSub" %>
> <div align="center">
> <table style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; FONT: 10pt
> verdana; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid"
> cellspacing="10">
> <tr>
> <td>
> <asp:Label id="lblUserName" runat="server" Font-Bold="true" Text="User
> Name:" />
> </td>
> <td>
> <asp:TextBox id="txtUserName" runat="server" />
> </td>
> </tr>
> <tr>
> <td>
> <asp:Label id="lblPassword" Font-Bold="True" Text="Password:"
> runat="server" />
> </td>
> <td>
> <asp:TextBox id="txtPassword" TextMode="Password" runat="server" />
> </td>
> </tr>
> </table>
> </div>
>
> UCSub.ascx.vb..
>
> Public Class UCSub
> Inherits System.Web.UI.UserControl
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
> Protected WithEvents lblUserName As System.Web.UI.WebControls.Label
> Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
> Protected WithEvents lblPassword As System.Web.UI.WebControls.Label
> Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
>
> 'NOTE: The following placeholder declaration is required by the Web
> Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> Public Sub ClearText()
> txtUserName.Text = ""
> txtPassword.Text = ""
> End Sub
>
> End Class
>
> UCSub.aspx..
>
> <%@ Register TagPrefix="DNJ" TagName="LoginControl" Src="UCSub.ascx" %>
> <%@ Page Language="vb" %>
> <HTML>
> <HEAD>
> <title>Using a Sub routine in a UserControl</title>
> <script runat="server">
> Sub btnSubmit_Click(Sender As Object, e As EventArgs)
>
> End Sub
>
> Sub btnClearText_Click(sender As Object, e As EventArgs)
> UC1.ClearText()
> End Sub
> </script>
> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body>
> <form id="form1" runat="server">
> <p></p>
> <DNJ:LoginControl id="UC1" runat="server" />
> <BR>
> <div align="center">
> <asp:Button id="btnSubmit" text="Submit" onclick="BtnSubmit_Click"
> runat="server" />
> <asp:Button id="btnClearText" text="Clear Text"
> OnClick="btnClearText_Click" runat="server" />
> <p></p>
> <asp:label id="lblMessage" runat="server" />
> </div>
> </form>
> </body>
> </HTML>
>
> UCSub.aspx.vb..
>
> Public Class UCSub1
> Inherits System.Web.UI.Page
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
> Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
> Protected WithEvents btnClearText As System.Web.UI.WebControls.Button
> Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> Protected WithEvents UC1 As System.Web.UI.UserControl
>
> 'NOTE: The following placeholder declaration is required by the Web
> Form Designer.
> 'Do not delete or move it.
> Private designerPlaceholderDeclaration As System.Object
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
>
> End Class
>
>
>
>





All times are GMT. The time now is 09:30 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.