Solved

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

Posted on 2004-08-21
2
938 Views
Last Modified: 2008-01-09
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 ;->
0
Comment
Question by:the_sleeper
2 Comments
 

Author Comment

by:the_sleeper
ID: 11862408
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!
0
 
LVL 20

Accepted Solution

by:
ihenry earned 500 total points
ID: 11862597

1. Yes, but not for every control as the article said it's only happen for user control
2. Yes
3. There's no patch available for this bug I know so far and I'm not sure if this issue will be fixed when the whidbey arrived.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save ms data to server side. 19 59
Linq asp.net mvc 13 22
Finding Events logs for IIS website that restarts 2 19
asp web application 3 36
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question