473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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.LoadControl(virtualPath);
3 string debug = control.ID;

but I got NullReferenceException 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 kr*************@just.ee as well.

Thanks in advance,

Kristjan
Jul 21 '05 #1
2 1403
Hi Kristjan,

Did you already ask this question in the newsgroup
microsoft.public.dotnet.framework.aspnet

That is a very active and quick answering newsgroup.

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

Cor
Jul 21 '05 #2
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 Sa****@discussions.microsoft.com> wrote in
message news:85**********************************@microsof t.com...
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.LoadControl(virtualPath);
3 string debug = control.ID;

but I got NullReferenceException 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 kr*************@just.ee as well.
Thanks in advance,

Kristjan

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kristjan Sander via .NET 247 | last post by:
Hello I am trying to write a #C windows desktop application that loadsan ascx file contents (user control) from file, initiates it andthen registers to database everything it finds. I tried...
2
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@...
1
by: Kristjan Sander | last post by:
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...
0
by: Kristjan Sander | last post by:
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...
1
by: John Cosmas | last post by:
I've got a page which loads up a different user control into a placeholder control every time a button is clicked on the parent page. I use a statement like...
2
by: Kristjan Sander | last post by:
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...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
1
by: Nathan Sokalski | last post by:
I am revieving the following error for one of my controls when loading any pages that use it: Server Error in '/exposure/app' Application....
2
by: Dave Alessi | last post by:
I migrated my project from VS 2003 to VS 2005. The application runs ok with a few exceptions, one being an ambigoius reference when loading a form. My application uses its own "master page"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.