Solved

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

Posted on 2004-08-21
2
939 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 88
asp.net mvc 2 44
Images showing on the internet -- asp.net -- VB.net.  Why some do and some don’t. 3 52
history of pages 7 55
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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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