Professional Web Applications Themes

Tpyesystem problem with ASP.NET UserControl. - ASP.NET Building Controls

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 ysis 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 ...

  1. #1

    Default Tpyesystem problem with ASP.NET UserControl.

    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 ysis 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 Guest

  2. #2

    Default RE: Tpyesystem problem with ASP.NET UserControl.

    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:
     
    Nathaniel Guest

  3. #3

    Default RE: Tpyesystem problem with ASP.NET UserControl.

    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 Guest

  4. #4

    Default Re: Tpyesystem problem with ASP.NET UserControl.

    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" <microsoft.com> wrote in
    message news:com... 


    Mark Guest

Similar Threads

  1. usercontrol problem
    By in forum ASP.NET Building Controls
    Replies: 0
    Last Post: March 23rd, 03:52 PM
  2. Problem with datagrid in userControl
    By Flare in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: November 24th, 09:59 AM
  3. Problem with a usercontrol
    By Amir Davoodi in forum ASP.NET Building Controls
    Replies: 1
    Last Post: August 21st, 07:21 AM
  4. OutputCache in usercontrol problem
    By marshal in forum ASP.NET General
    Replies: 3
    Last Post: August 7th, 07:26 AM
  5. Replies: 1
    Last Post: July 3rd, 03:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139