Tpyesystem problem with ASP.NET UserControl.

Discussion in 'ASP .Net Building Controls' started by Michael Lierheimer, Jan 25, 2007.

  1. Hallo.

    After migration from ASP1.0 to ASP 2.0 I have the following problem. The
    migrated code does not compile. I get an error: "Cannot implicitly convert
    type 'NetView.WebUI.ctlSubDevice' to 'ASP.distributor_ctlsubdevice_ascx'.
    An explicit conversion exists ...."

    The line in the code behind file is:
    ctlSubDevice = (NetView.WebUI.ctlSubDevice) this.FindControl("ctlSubDevice");
    This code it worked in ASP.NET 1.0. An analysis of the problem showed that
    the type ot the ctlSubDevice, which is NetView.WebUI.ctlSubDevice, was
    implict convert to ASP.distributor_ctlsubdevice_ascx. So the cast fails.

    In the aspx file, the control is registered with:
    <%@ Reference Control="~/distributor/ctlsubdevice.ascx" %>
    <%@ Register TagPrefix="uc1" TagName="ctlSubDevice" Src="ctlSubDevice.ascx" %>

    Does anybody has a solution for this problem, or did I missed something ;)

    Yours
    Michael
    Michael Lierheimer, Jan 25, 2007
    #1
    1. Advertising

  2. What is the declaration for ctlSubDevice? Did you put it in a namespace?
    From the looks of it it seems like it is in it's own namespace and not the
    namespace that you gave it.
    all controls are by default in the ASP namespace when no namespace is
    provided.

    I'd check to make sure that the namespace is set and that the .ascx maps to
    the proper .ascx.cs . This link may have been broken and it may have created
    a default file.

    Hope this helps.

    "Michael Lierheimer" wrote:

    > Hallo.
    >
    > After migration from ASP1.0 to ASP 2.0 I have the following problem. The
    > migrated code does not compile. I get an error: "Cannot implicitly convert
    > type 'NetView.WebUI.ctlSubDevice' to 'ASP.distributor_ctlsubdevice_ascx'.
    > An explicit conversion exists ...."
    >
    > The line in the code behind file is:
    > ctlSubDevice = (NetView.WebUI.ctlSubDevice) this.FindControl("ctlSubDevice");
    > This code it worked in ASP.NET 1.0. An analysis of the problem showed that
    > the type ot the ctlSubDevice, which is NetView.WebUI.ctlSubDevice, was
    > implict convert to ASP.distributor_ctlsubdevice_ascx. So the cast fails.
    >
    > In the aspx file, the control is registered with:
    > <%@ Reference Control="~/distributor/ctlsubdevice.ascx" %>
    > <%@ Register TagPrefix="uc1" TagName="ctlSubDevice" Src="ctlSubDevice.ascx" %>
    >
    > Does anybody has a solution for this problem, or did I missed something ;)
    >
    > Yours
    > Michael
    Nathaniel Greene, Jan 26, 2007
    #2
    1. Advertising

  3. Hallo.

    Thanks for your help, but we use the Namespace "NetView.WebUi" for all of
    our controls. Below is the definition of the control.

    Definition of Namespace and Class in distributor\ctlSubDevice.ascx.cs:
    namespace NetView.WebUI
    {
    using System;
    using ....
    using System.Drawing;

    public partial class ctlSubDevice : System.Web.UI.UserControl
    { ....

    Control definition in distristributor\ctlSubDevice.ascx:
    <%@ Control Language="c#" Inherits="NetView.WebUI.ctlSubDevice"
    CodeFile="ctlSubDevice.ascx.cs" %>

    Yours
    Michael Lierheimer
    MCSD, MCSD.NET, MCPD EA
    Michael Lierheimer, Jan 26, 2007
    #3
  4. Michael,
    What is the actual ID of the control. ctlSubDevice is the tagname
    suchas <uc1:ctlSubDevice runat="server"... but is this the same as the id
    assigned to the control? Often, when a control is dragged onto the designer
    it will name the control to match the tagname, but add a 1 such as
    ctlSubDevice1. So your tag may look like <uc1:ctlSubDevice
    Id="ctlSubDevice1" runat="server"></uc1ctlSubDevice> so the name of the
    control is actually ctlSubDevice.

    You don't need to do any casting or use findcontrol at all. In the
    codebehind just create a protected variable of the same name as the
    control's id.

    protected NetView.WebUI.ctlSubDevice ctlSubDevice1;


    --

    Hope this helps,
    Mark Fitzpatrick
    Former Microsoft FrontPage MVP 199?-2006



    "Michael Lierheimer" <> wrote in
    message news:...
    > Hallo.
    >
    > After migration from ASP1.0 to ASP 2.0 I have the following problem. The
    > migrated code does not compile. I get an error: "Cannot implicitly convert
    > type 'NetView.WebUI.ctlSubDevice' to 'ASP.distributor_ctlsubdevice_ascx'.
    > An explicit conversion exists ...."
    >
    > The line in the code behind file is:
    > ctlSubDevice = (NetView.WebUI.ctlSubDevice)
    > this.FindControl("ctlSubDevice");
    > This code it worked in ASP.NET 1.0. An analysis of the problem showed that
    > the type ot the ctlSubDevice, which is NetView.WebUI.ctlSubDevice, was
    > implict convert to ASP.distributor_ctlsubdevice_ascx. So the cast fails.
    >
    > In the aspx file, the control is registered with:
    > <%@ Reference Control="~/distributor/ctlsubdevice.ascx" %>
    > <%@ Register TagPrefix="uc1" TagName="ctlSubDevice"
    > Src="ctlSubDevice.ascx" %>
    >
    > Does anybody has a solution for this problem, or did I missed something ;)
    >
    > Yours
    > Michael
    Mark Fitzpatrick, Jan 26, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    682
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    409
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,539
  4. Phl
    Replies:
    2
    Views:
    521
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  5. Mark van Bree

    Postback problem with usercontrol in usercontrol

    Mark van Bree, May 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    163
Loading...

Share This Page