Solved

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

Posted on 2004-08-21
2
933 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
Comment Utility
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
Comment Utility

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now