By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

User Control not showing properties

P: n/a
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):

<%@ Page Language="VB" AutoEventWireup="true" Trace="true"
CodeFile="TakeSurveyTest.aspx.vb" Inherits="TakeSurveyTest" %>
....
<div visible="true" runat="server">
<asp:PlaceHolder ID="ContactInfo" runat="server"/<br />
<--------------The error
<asp:Button ID="SubmitContact" Text="Submit Contact"
OnClick="SaveContact_Click" runat="server" /><br />
</div>

The ContactInfo control (ContactInfo.ascx):

<%@ Control Language="VB" AutoEventWireup="true"
CodeFile="ContactInfo.ascx.vb" Inherits="ContactInfo" %>

<td class="style4">
<asp:TextBox ID="objFirstName" Width="120px" runat="server" />
</td>
<td class="style2">
<asp:TextBox ID="objMiddleName" Width="120px" runat="server" />
</td>

And the ContactInfo.ascx.vb:

Imports System.Data
Imports System.Data.SqlClient
Imports MyFunctions.BitHandling
Imports System.Drawing
Imports MyFunctions
Imports RolesBasedAuthentication

Partial Class ContactInfo
Inherits System.Web.UI.UserControl
....
Public Property FirstName() As String
Get
Return objFirstName.Text
End Get
Set(ByVal value As String)
objFirstName.Text = Value
End Set
End Property

Public Property LastName() As String
Get
Return objLastName.Text
End Get
Set(ByVal value As String)
objLastName.Text = Value
End Set
End Property
So the properties are being defined but in the TakeSurveyTest.aspx.vb file
is saying ContactInfo doesn't have these properties. I load the conrol in
my PageLoad as:

ContactInfo.Controls.Add(LoadControl("~/ContactInfo.ascx"))

But these lines give me the error:

parameters(1).Value = ContactInfo.FirstName
parameters(2).Value = ContactInfo.LastName

The error is:

'FirstName' is not a member of 'System.Web.UI.WebControls.PlaceHolder'

Which is true, but how do access the ContactInfo parameters?

Thanks,

Tom

Oct 5 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I can statically do this by registering the control:

<%@ Register TagPrefix="uc" TagName="ContactInfo" Src="contactInfo.ascx" %>

and then change the Placeholder line to:

<uc:ContactInfo ID="ContactInfo" runat="server" />

Then the information errors go away because not the "ContactInfo" points to
UserControl (ControlInfo.ascx).

But if I use loadControl and Add to the control, I can't seem to use the
properties.

There must be a way to do this?

Thanks,

Tom

"tshad" <tf*@dslextreme.comwrote in message
news:eE**************@TK2MSFTNGP06.phx.gbl...
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):

<%@ Page Language="VB" AutoEventWireup="true" Trace="true"
CodeFile="TakeSurveyTest.aspx.vb" Inherits="TakeSurveyTest" %>
...
<div visible="true" runat="server">
<asp:PlaceHolder ID="ContactInfo" runat="server"/<br />
<--------------The error
<asp:Button ID="SubmitContact" Text="Submit Contact"
OnClick="SaveContact_Click" runat="server" /><br />
</div>

The ContactInfo control (ContactInfo.ascx):

<%@ Control Language="VB" AutoEventWireup="true"
CodeFile="ContactInfo.ascx.vb" Inherits="ContactInfo" %>

<td class="style4">
<asp:TextBox ID="objFirstName" Width="120px" runat="server" />
</td>
<td class="style2">
<asp:TextBox ID="objMiddleName" Width="120px" runat="server" />
</td>

And the ContactInfo.ascx.vb:

Imports System.Data
Imports System.Data.SqlClient
Imports MyFunctions.BitHandling
Imports System.Drawing
Imports MyFunctions
Imports RolesBasedAuthentication

Partial Class ContactInfo
Inherits System.Web.UI.UserControl
...
Public Property FirstName() As String
Get
Return objFirstName.Text
End Get
Set(ByVal value As String)
objFirstName.Text = Value
End Set
End Property

Public Property LastName() As String
Get
Return objLastName.Text
End Get
Set(ByVal value As String)
objLastName.Text = Value
End Set
End Property
So the properties are being defined but in the TakeSurveyTest.aspx.vb file
is saying ContactInfo doesn't have these properties. I load the conrol in
my PageLoad as:

ContactInfo.Controls.Add(LoadControl("~/ContactInfo.ascx"))

But these lines give me the error:

parameters(1).Value = ContactInfo.FirstName
parameters(2).Value = ContactInfo.LastName

The error is:

'FirstName' is not a member of 'System.Web.UI.WebControls.PlaceHolder'

Which is true, but how do access the ContactInfo parameters?

Thanks,

Tom

Oct 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.