Reflection in ASP.NET - Strange behavior?

Discussion in 'ASP .Net' started by Justice Gray, Oct 15, 2003.

  1. Justice Gray

    Justice Gray Guest

    I have the following code encapsulated in an ascx page (user control):

    namespace MyCompany.Web.UserControls
    {
    [most of my code]
    string webform_namespace = this.GetType().Namespace.ToString();
    }

    Now, when I run this and output the string to the trace information, I
    get the following value:

    "ASP"

    However, I want the value to be "MyCompany.Web.UserControls", which is
    the namespace where I've defined it...pretty much the way I'd expect
    this to show up if I was running this as a Windows form.

    Is there any way to do this? Why is the namespace showing up as
    "ASP"? Is this a default value? If so, is there any way to override
    this?

    Thanks,
    -Justice
     
    Justice Gray, Oct 15, 2003
    #1
    1. Advertising

  2. Justice,

    You need to check the Namespace of the base type. Change your code to this:

    string webform_namespace = this.GetType().BaseType.Namespace.ToString();


    Jim Cheshire [MSFT]
    Developer Support
    ASP.NET


    This post is provided as-is with no warranties and confers no rights.

    --------------------
    >From: (Justice Gray)
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >Subject: Reflection in ASP.NET - Strange behavior?
    >Date: 15 Oct 2003 09:08:54 -0700
    >Organization: http://groups.google.com
    >Lines: 23
    >Message-ID: <>
    >NNTP-Posting-Host: 64.42.208.35
    >Content-Type: text/plain; charset=ISO-8859-1
    >Content-Transfer-Encoding: 8bit
    >X-Trace: posting.google.com 1066234135 16770 127.0.0.1 (15 Oct 2003

    16:08:55 GMT)
    >X-Complaints-To:
    >NNTP-Posting-Date: Wed, 15 Oct 2003 16:08:55 +0000 (UTC)
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnews1.google.com!no
    t-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:184351
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >I have the following code encapsulated in an ascx page (user control):
    >
    >namespace MyCompany.Web.UserControls
    >{
    > [most of my code]
    > string webform_namespace = this.GetType().Namespace.ToString();
    >}
    >
    >Now, when I run this and output the string to the trace information, I
    >get the following value:
    >
    >"ASP"
    >
    >However, I want the value to be "MyCompany.Web.UserControls", which is
    >the namespace where I've defined it...pretty much the way I'd expect
    >this to show up if I was running this as a Windows form.
    >
    >Is there any way to do this? Why is the namespace showing up as
    >"ASP"? Is this a default value? If so, is there any way to override
    >this?
    >
    >Thanks,
    >-Justice
    >
     
    Jim Cheshire [MSFT], Oct 15, 2003
    #2
    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. Satheesh

    Reflection in ASP.net

    Satheesh, Dec 3, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    473
    Satheesh Kumar
    Dec 6, 2003
  2. Felipe Garcia

    IIS6 and ASP.NET Whidbey strange behavior

    Felipe Garcia, Jan 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    491
    David Wang [Msft]
    Jan 15, 2005
  3. Mossman
    Replies:
    1
    Views:
    531
    cbDevelopment
    Dec 12, 2005
  4. Kursat

    (ASP.NET 2.0 - GridView) Strange behavior!

    Kursat, Jun 12, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    102
    Kursat
    Jun 12, 2007
  5. Ray Deese

    Managed C++ Web Service - strange reflection problems

    Ray Deese, May 6, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    130
    Ray Deese
    May 6, 2004
Loading...

Share This Page