Solved

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

Posted on 2004-08-21
2
940 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

632 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