Error Setting user control property at web form

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Error Setting user control property at web form

    Dear Friends
    Hope things goes well to you. I have this problem. Would you please give me
    your solution?

    I want to change a property that I define on my user control in my web form
    that contains that user control.
    but when I want to set the property of user control at my web form, got this
    error
    c:\inetpub\wwwroot\test4\WebForm1.aspx.vb(19): Name 'Uc1' is not declared.
    How can I solve this problem. Please help.
    Thank you very much in advance and please me your answer to my email:
    [email]aeshterayeh@hotmail.com[/email] if possible.

    Best Regards
    Amir Eshterayeh
    [email]aeshterayeh@hotmail.com[/email]


    this is the code behind (vb code) of my web form

    ----------------------------------------------------------------------------
    -----------------------------
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Uc1.Username = "Message text changed!"
    End Sub
    ----------------------------------------------------------------------------
    -----------------------------

    This is the user control code
    ----------------------------------------------------------------------------
    -----------------------------

    Public MustInherit Class uc
    Inherits System.Web.UI.UserControl
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Public Username As String

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    Label1.Text = Username
    End Sub

    End Class
    ----------------------------------------------------------------------------
    -----------------------------
    this is the user control HTML
    ----------------------------------------------------------------------------
    -----------------------------

    <%@ Control Language="vb" AutoEventWireup="false" Codebehind="uc.ascx.vb"
    Inherits="test4.uc"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

    <asp:Label id="Label1" runat="server">Label</asp:Label>
    ----------------------------------------------------------------------------
    -----------------------------
    this is the HTML Code my Web form that contains my user control
    ----------------------------------------------------------------------------
    -----------------------------
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
    Inherits="test4.WebForm1"%>
    <%@ Register TagPrefix="uc1" TagName="uc" Src="uc.ascx" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <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 MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">

    <uc1:uc id="Uc1" runat="server"></uc1:uc>

    </form>
    </body>
    </HTML>
    ----------------------------------------------------------------------------
    -----------------------------



    Amir Eshterayeh Guest

  2. Similar Questions and Discussions

    1. Web user control creation - Resolve an ImageUrl property if control themed
      Hi I'm creating a WebControl which has a themeable ImageUrl property : <Bindable(True), Category("Appearance"),...
    2. Modifying a property of a control contained in a user control
      I have a user control that is made up of several HyperLink controls. In the Page_Load event of pages that use the control I want to change a...
    3. Composite Control Property Setting Problem
      I have built a simple composite control that consists of a textbox, requiredfieldvalidator and rangevalidator. For properties that are unique to...
    4. Setting user control property dynamically?
      Hi I created a user control that has a property that accepts a url ("NavUrl").. I tried to set the value as follows directly in the aspx page...
    5. Setting a control property
      I have a custom composite control which reads in information from an XML file in its createchildcontrols() event. I would like to be able to set...
  3. #2

    Default Re: Error Setting user control property at web form

    Hi,

    You need to have a member declaration for the user control at the Page as
    you have already for the Label in the user control.That means a member whose
    name matches the ID of the user control and type matches the code-behinc
    class type of the UC.

    Protected WithEvents Uc1 As uc

    (Please do not cross-post)

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "Amir Eshterayeh" <aeshterayeh@yahoo.com> wrote in message
    news:O2wpiyHtDHA.2456@TK2MSFTNGP12.phx.gbl...
    > Dear Friends
    > Hope things goes well to you. I have this problem. Would you please give
    me
    > your solution?
    >
    > I want to change a property that I define on my user control in my web
    form
    > that contains that user control.
    > but when I want to set the property of user control at my web form, got
    this
    > error
    > c:\inetpub\wwwroot\test4\WebForm1.aspx.vb(19): Name 'Uc1' is not
    declared.
    > How can I solve this problem. Please help.
    > Thank you very much in advance and please me your answer to my email:
    > [email]aeshterayeh@hotmail.com[/email] if possible.
    >
    > Best Regards
    > Amir Eshterayeh
    > [email]aeshterayeh@hotmail.com[/email]
    >
    >
    > this is the code behind (vb code) of my web form
    >
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > Uc1.Username = "Message text changed!"
    > End Sub
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    >
    > This is the user control code
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    >
    > Public MustInherit Class uc
    > Inherits System.Web.UI.UserControl
    > Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    > Public Username As String
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    >
    > Label1.Text = Username
    > End Sub
    >
    > End Class
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    > this is the user control HTML
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    >
    > <%@ Control Language="vb" AutoEventWireup="false" Codebehind="uc.ascx.vb"
    > Inherits="test4.uc"
    > TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    >
    > <asp:Label id="Label1" runat="server">Label</asp:Label>
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    > this is the HTML Code my Web form that contains my user control
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    > <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="WebForm1.aspx.vb"
    > Inherits="test4.WebForm1"%>
    > <%@ Register TagPrefix="uc1" TagName="uc" Src="uc.ascx" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <title>WebForm1</title>
    > <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 MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    >
    > <uc1:uc id="Uc1" runat="server"></uc1:uc>
    >
    > </form>
    > </body>
    > </HTML>
    > --------------------------------------------------------------------------
    --
    > -----------------------------
    >
    >
    >

    Teemu Keiski Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139