User Control not showing properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    #1

    User Control not showing properties

    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="TakeS urveyTest.aspx. vb" Inherits="TakeS urveyTest" %>
    ....
    <div visible="true" runat="server">
    <asp:PlaceHolde r ID="ContactInfo " runat="server"/<br />
    <--------------The error
    <asp:Button ID="SubmitConta ct" Text="Submit Contact"
    OnClick="SaveCo ntact_Click" runat="server" /><br />
    </div>

    The ContactInfo control (ContactInfo.as cx):

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

    <td class="style4">
    <asp:TextBox ID="objFirstNam e" Width="120px" runat="server" />
    </td>
    <td class="style2">
    <asp:TextBox ID="objMiddleNa me" Width="120px" runat="server" />
    </td>

    And the ContactInfo.asc x.vb:

    Imports System.Data
    Imports System.Data.Sql Client
    Imports MyFunctions.Bit Handling
    Imports System.Drawing
    Imports MyFunctions
    Imports RolesBasedAuthe ntication

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

    Public Property LastName() As String
    Get
    Return objLastName.Tex t
    End Get
    Set(ByVal value As String)
    objLastName.Tex t = 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.Con trols.Add(LoadC ontrol("~/ContactInfo.asc x"))

    But these lines give me the error:

    parameters(1).V alue = ContactInfo.Fir stName
    parameters(2).V alue = ContactInfo.Las tName

    The error is:

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

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

    Thanks,

    Tom



  • tshad

    #2
    Re: User Control not showing properties

    I can statically do this by registering the control:

    <%@ Register TagPrefix="uc" TagName="Contac tInfo" Src="contactInf o.ascx" %>

    and then change the Placeholder line to:

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

    Then the information errors go away because not the "ContactInf o" points to
    UserControl (ControlInfo.as cx).

    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" <tfs@dslextreme .comwrote in message
    news:eEVNz2yJJH A.1936@TK2MSFTN GP06.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="TakeS urveyTest.aspx. vb" Inherits="TakeS urveyTest" %>
    ...
    <div visible="true" runat="server">
    <asp:PlaceHolde r ID="ContactInfo " runat="server"/<br />
    <--------------The error
    <asp:Button ID="SubmitConta ct" Text="Submit Contact"
    OnClick="SaveCo ntact_Click" runat="server" /><br />
    </div>
    >
    The ContactInfo control (ContactInfo.as cx):
    >
    <%@ Control Language="VB" AutoEventWireup ="true"
    CodeFile="Conta ctInfo.ascx.vb" Inherits="Conta ctInfo" %>
    >
    <td class="style4">
    <asp:TextBox ID="objFirstNam e" Width="120px" runat="server" />
    </td>
    <td class="style2">
    <asp:TextBox ID="objMiddleNa me" Width="120px" runat="server" />
    </td>
    >
    And the ContactInfo.asc x.vb:
    >
    Imports System.Data
    Imports System.Data.Sql Client
    Imports MyFunctions.Bit Handling
    Imports System.Drawing
    Imports MyFunctions
    Imports RolesBasedAuthe ntication
    >
    Partial Class ContactInfo
    Inherits System.Web.UI.U serControl
    ...
    Public Property FirstName() As String
    Get
    Return objFirstName.Te xt
    End Get
    Set(ByVal value As String)
    objFirstName.Te xt = Value
    End Set
    End Property
    >
    Public Property LastName() As String
    Get
    Return objLastName.Tex t
    End Get
    Set(ByVal value As String)
    objLastName.Tex t = 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.Con trols.Add(LoadC ontrol("~/ContactInfo.asc x"))
    >
    But these lines give me the error:
    >
    parameters(1).V alue = ContactInfo.Fir stName
    parameters(2).V alue = ContactInfo.Las tName
    >
    The error is:
    >
    'FirstName' is not a member of 'System.Web.UI. WebControls.Pla ceHolder'
    >
    Which is true, but how do access the ContactInfo parameters?
    >
    Thanks,
    >
    Tom
    >
    >
    >

    Comment

    Working...