loading ascx from windows desktop application?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kristjan Sander

    #1

    loading ascx from windows desktop application?

    Hello

    I am trying to write a #C windows desktop application that loads an ascx file contents (user control) from file, initiates it and then registers to database everything it finds. I tried that way:

    1 Page page=new Page();
    2 Control control=page.Lo adControl(virtu alPath);
    3 string debug = control.ID;

    but I got NullReferenceEx ception on the 2nd line.

    From earlier post http://www.dotnet247.com/247referenc...29/148858.aspx
    I found out that to create a control dynamically, one first needs to include className into the ascx and to register the control in page. My brand new dynamically created page object of course lacks that registration and I guess that's why the LoadControl method does not work.

    Is anybody able to explain, how to properly look up the contents of an ascx file?

    I would appreciate if you sent all answers directly to kristjan.sander @just.ee as well.

    Thanks in advance,

    Kristjan
  • Cor Ligthert

    #2
    Re: loading ascx from windows desktop application?

    Hi Kristjan,

    Did you already ask this question in the newsgroup
    microsoft.publi c.dotnet.framew ork.aspnet

    That is a very active and quick answering newsgroup.

    I think that with your question you have the best change there.

    Cor


    Comment

    • Marina

      #3
      Re: loading ascx from windows desktop application?

      I don't think the registration is your problem. LoadControl is used when
      there are no registrations. When user controls are explicitly registered,
      they is usually an instance of them on the page as well, as opposed to
      dynamically loading them via LoadControl.

      I think your problem lies in the fact that you are creating an instance of
      Page, and not ASP.NET. Your instance of page has no Request, Reponse, etc -
      how could it? It was not created from a web request, so it cannot have a web
      context. And I believe that is where your problem lies.

      I would imagine simulating everything that ASP.NET does and create a fake
      http context would be extermely difficult.

      "Kristjan Sander" <Kristjan Sander@discussi ons.microsoft.c om> wrote in
      message news:85778798-F012-4DB9-B6FC-12EB5A5BF1C2@mi crosoft.com...[color=blue]
      > Hello
      >
      > I am trying to write a #C windows desktop application that loads an ascx[/color]
      file contents (user control) from file, initiates it and then registers to
      database everything it finds. I tried that way:[color=blue]
      >
      > 1 Page page=new Page();
      > 2 Control control=page.Lo adControl(virtu alPath);
      > 3 string debug = control.ID;
      >
      > but I got NullReferenceEx ception on the 2nd line.
      >
      > From earlier post[/color]
      http://www.dotnet247.com/247referenc...29/148858.aspx[color=blue]
      > I found out that to create a control dynamically, one first needs to[/color]
      include className into the ascx and to register the control in page. My
      brand new dynamically created page object of course lacks that registration
      and I guess that's why the LoadControl method does not work.[color=blue]
      >
      > Is anybody able to explain, how to properly look up the contents of an[/color]
      ascx file?[color=blue]
      >
      > I would appreciate if you sent all answers directly to[/color]
      kristjan.sander @just.ee as well.[color=blue]
      >
      > Thanks in advance,
      >
      > Kristjan[/color]


      Comment

      Working...