Link to home
Start Free TrialLog in
Avatar of the_sleeper
the_sleeperFlag for United States of America

asked on

USERCONTROLS: "Control is not declared" ????

Ok, I need a little help here...

I am trying to programmatically expose two properties of a custom (example) control using Visual Studio.net (VS.Net) on Win XP.

Here's what I am doing:

1.) In VS.Ne, I create a new "web user control"
2.) on the control I add the following code:
=======[ uc_Control.ascx ]=======
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="uc_Control.ascx.vb" Inherits="TYSAPDOTNET.uc_Control" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

<p><font color="<%=color%>"><%=Text%></font></p> ' <!-- what i added
=======[ end ]=======


3.) In the code behind FOR THE UER CONTROL I added the following:

=======[ uc_Control.ascx.vb ]=======
Public Class uc_Control
    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

    '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 color As String '<!-- I ADDED THIS
    Public text As String   '<!-- I ADDED THIS

End Class
=======[ end ]=======

4.) I then created a "container"  .aspx page to test the control. On the .aspx page I added two controls:

      a. On the first control [ Uc_Control1 ] is set both the COLOR and TEXT properties.
      b. For the second control, i sought to SET THE PROPERTIES PROGRAMMATICALLY (see #5)
         ...and that's where all @%*!! broke loose

=======[ uc_Container.aspx ]=======
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="uc_Container.aspx.vb" Inherits="TYSAPDOTNET.uc_Container"%>
<%@ Register TagPrefix="uc1" TagName="uc_Control" Src="uc_Control.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
  <HEAD>
    <title>uc_Container</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <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_Control id=Uc_Control1  TEXT="THIS IS A TEST" color="green" runat="server"></uc1:uc_Control><br>
    <uc1:uc_Control id=Uc_Control2 runat="server"></uc1:uc_Control>
   
    </form>

  </body>
</HTML>
=======[ end ]=======

5.) I then opened the .aspx code behind file and entered the code to set properties for [ Uc_Control2 ] , but I keep gettintg the (oh so familiar) "blue-squigglies" which is telling me ....

    "NAME 'Uc_Control2' is not declared"

Worse yet, it does'nt seem to matter if it's in the page_load or out (i'm not sure where it goes)

=======[ uc_Container.aspx.vb ]=======
Public Class uc_Container
    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

    '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

        Uc_Control2.text = "test" '<!-- THIS IS WHERE I ATTEMPT TO SET THE [TEXT] PROPERTY

    End Sub

End Class
=======[ end

Oh enlightened ones....little help? It's killin me ;->
Avatar of the_sleeper
the_sleeper
Flag of United States of America image

ASKER

Since posting tis question, I have discovered that there is a *BUG* in VS (figures) and I am missing a declaration
(see: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q316370&GSSNB=1 )

thus I added:

    Protected WithEvents Uc_Control1 As uc_Control
    Protected WithEvents Uc_Control2 As Uc_Control

which modifies my question:

   1. Does this mean that i must add individual declarations for EVERY control I add to the page?
   2. is this the ONLY declaration i must include?
   3. why the heck has MS not PATCHED this bug!

thanks!
ASKER CERTIFIED SOLUTION
Avatar of ihenry
ihenry

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial