Multiple controls, Same name

Discussion in 'ASP .Net Building Controls' started by Michael Tissington, Jul 14, 2003.

  1. I have created multiple controls with the same name but in different
    namespaces (each one in a different folder)

    I now need to reference these controls on a single web page but when I try
    to browse the page I get errors saying the the control is defined more than
    once.

    How do I make each reference specific?

    This is what I have at the moment

    <@ Register TagPrefix="uc1" TagName="Test1" Src="/Test1/Description.ascx"
    %>
    <@ Register TagPrefix="uc1" TagName="Test2" Src="/Test2/Description.ascx"
    %>
    <@ Register TagPrefix="uc1" TagName="Test3" Src="/Test3/Description.ascx"
    %>
     
    Michael Tissington, Jul 14, 2003
    #1
    1. Advertisements

  2. Hi Michael,

    What you're seeing is okay and it has to do with the way the parser generate
    implicit class names. You could use the ClassName attribute in the @Control
    directive of your .ascx to avoid having duplicate names.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.
     
    Victor Garcia Aprea [MVP], Jul 15, 2003
    #2
    1. Advertisements

  3. Hi Michael,

    What you're seeing is okay and it has to do with the way the parser generate
    implicit class names. You could use the ClassName attribute in the @Control
    directive of your .ascx to avoid having duplicate names.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.
     
    Victor Garcia Aprea [MVP], Jul 15, 2003
    #3
  4. Thanks
     
    Michael Tissington, Jul 15, 2003
    #4
  5. Hi,

    I agree with Victor.

    When ASP .NET parse the application, by default it will create the class of
    the corresponding control with the name of the control¡¯s file name. If the
    file names of the controls are the same, classes with the same name will be
    created and the error will occur. If you go to the folder
    Windows\Microsoft.NET\Framework\<version>\Temporary ASP.NET Files\<random
    number>, you will find several *.vb or *.cs files. These files are the
    results of the parsing. You will notice that in these .VB or .CS files,
    Description_ascx class may have been defined several times.

    To resolve the issue, add a ¡°ClassName=¡± attribute to the @Control
    reference in the ascx :

    <%@ Control ClassName="myclass1" Language="vb"¡­

    Name the controls different names as ClassName. We don¡¯t need to modify
    the aspx file.


    Best regards,
    Bradley Jiang

    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    |From: "Michael Tissington" <>
    |Subject: Multiple controls, Same name
    |Date: Sun, 13 Jul 2003 21:26:49 -0700
    |Lines: 25
    |X-Priority: 3
    |X-MSMail-Priority: Normal
    |X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    |X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    |Message-ID: <#>
    |Newsgroups:
    microsoft.public.dotnet.framework.aspnet.buildingcontrols,microsoft.public.d
    otnet.framework.aspnet.webcontrols
    |NNTP-Posting-Host: antelope.oaklodge.com 63.67.71.5
    |Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    |Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:13074
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:6570
    |X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    |I have created multiple controls with the same name but in different
    |namespaces (each one in a different folder)
    |
    |I now need to reference these controls on a single web page but when I try
    |to browse the page I get errors saying the the control is defined more than
    |once.
    |
    |How do I make each reference specific?
    |
    |This is what I have at the moment
    |
    |<@ Register TagPrefix="uc1" TagName="Test1" Src="/Test1/Description.ascx"
    |%>
    |<@ Register TagPrefix="uc1" TagName="Test2" Src="/Test2/Description.ascx"
    |%>
    |<@ Register TagPrefix="uc1" TagName="Test3" Src="/Test3/Description.ascx"
    |%>
    |
    |--
    |Michael Tissington
    |Oaklodge Technologies
    |http://www.oaklodge.com/technology
    |
    |
    |
    |
     
    Bradley Jiang[MSFT], Jul 18, 2003
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...