473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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


Nov 25 '05 #1
2 3718
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" <bo***@hotmail.com> wrote in message
news:e_********************@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

Nov 28 '05 #2
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" <bo***@hotmail.com> wrote in message
news:e_********************@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

Dec 4 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sushil Srivastava | last post by:
Hi Guys, Would you be able to help me using C# GUI (with user interface component) in my MFC application. I have used managed extension, COM-interops, etc but problem is this C# component has...
1
by: abjork | last post by:
I have a aspx page with two user controls. One of them holds some properties that I would like to set from the other user control. How do I do that I keep getting "Object reference not set to an...
1
by: Chris | last post by:
novice question here... I am building a registration form while learning Asp.Net. I am having trouble passing data between "dynamically"-added server controls. To simplify, I have a single...
1
by: Lan H. Nguyen | last post by:
I used the technique from this article http://msdn.microsoft.com/asp.net/using/building/webcontrols/default.aspx?pull=/library/en-us/dnaspp/html/usercontrols.asp, that set the properties to...
6
by: Paul | last post by:
Hi I am trying to conditionally hide a user control on a form in the code. There is a visible element in the properties box of the user control but in the .vb file (in the code) the object does not...
4
by: rmccinc | last post by:
Hello- I am missing something very easy here I think. I have 3 files test.master.vb (Master) content.aspx.vb (content) Control.ascx.vb (user Control)
2
by: jesl | last post by:
Group, I have created a User Control with the property "Html" of type string. If I declare this control on an ASPX page with the value "<b>This is an entity: &lt;</b>" for the property "Html", the...
2
by: Sasquatch | last post by:
I'm still having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight...
1
by: tshad | last post by:
In VB 2008, I have a user control added to the page in the PageLoad event - but the properties are causing me an error. The program (TakeSurveyTest.aspx) using the control (ContactInfo): <%@...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.