473,396 Members | 2,154 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,396 software developers and data experts.

Template.LoadControl(type,object[])...doesn't work as expected

Maybe my expectations are just too low because I haven't read much
documentation on this method, but basically, I am trying to load a user
control dynamically without using a virtual path (I have disabled
FileIOPermission beyond AllLocalFiles, and it appears that
LoadControl(string) calls Server.MapPath, which needs greater access). What
I am attempting to do is just pass in my UC type:
Control ctrl = this.Page.LoadControl(TestApp.Controls.MyUserContr ol, null);

but when I do this, the control doesn't show up. I've looked at the
differences between controls loaded this way and via virtual path, as the
virtual path version displays just fine. The underlying types, however are
different. The virtualpath one is of type "ASP.MyUserControl_aspx" whereas
the one loaded from type is TestApp.Controls.MyUserControl and also lacks
TemplateXXXX properties. Am I somehow misuing LoadControl(type, object[])
or is there a bug that prevents dynamic control loading like this?
Nov 19 '05 #1
2 3650
you are loading the codebehind class, so if the code behind depends on
anything in the aspx file, it won't work. the loadcontrol from virtual path
will compile the aspx page if needed, and uses its class, not the codebehind
class.

you should switch to server (code only) controls if you want to use this
technique.

-- bruce (sqlwork.com)
"Keith Patrick" <ri*******************@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Maybe my expectations are just too low because I haven't read much
documentation on this method, but basically, I am trying to load a user
control dynamically without using a virtual path (I have disabled
FileIOPermission beyond AllLocalFiles, and it appears that
LoadControl(string) calls Server.MapPath, which needs greater access).
What I am attempting to do is just pass in my UC type:
Control ctrl = this.Page.LoadControl(TestApp.Controls.MyUserContr ol,
null);

but when I do this, the control doesn't show up. I've looked at the
differences between controls loaded this way and via virtual path, as the
virtual path version displays just fine. The underlying types, however
are different. The virtualpath one is of type "ASP.MyUserControl_aspx"
whereas the one loaded from type is TestApp.Controls.MyUserControl and
also lacks TemplateXXXX properties. Am I somehow misuing
LoadControl(type, object[]) or is there a bug that prevents dynamic
control loading like this?

Nov 19 '05 #2
I knew it worked that way in 1.1, but I would think that since 2.0
implements them as partial classes, they would be linked together at compile
time such that my namespace-qualified classname also corresponds to the
full, non-partial class, since I can go into TestApp.Controls.MyUserControl
and reference controls that have only been declared in the codebehind at
design-time.
Nov 20 '05 #3

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

Similar topics

2
by: CoolPint | last post by:
As a self-exercise, I am trying to write a generic Priority Queue, which would store any type and and accept any user-definable "priority" function. After much tinkering, I came up with...
2
by: JT | last post by:
I have a compiler error when using a non-dependent type declared in a template, if I use the type in function definitions. I think it is a parsing issues related to confusion with a typename. ...
2
by: verec | last post by:
Consider a first version: --- drawable.hpp --- #include "gcdata.hpp" struct drawable { ... virtual int internal_new_GC(gcdata * gcd) = 0 ; } ; --- gcdata.hpp ---
5
by: Axter | last post by:
I'm fine tuning a scope_handle class that takes a policy class as the second template. http://code.axter.com/scope_handle.h Please see above link for full understanding of the problem. One...
4
by: PengYu.UT | last post by:
The following shows the source code and the error message(from g++-3.3). I wrote two assignment operator. One is for the same type case, the other one is for different type case. I'm wondering why...
0
by: DC | last post by:
Hi, thankfully this new method exists in the 2.0 Framework, in 1.1 it was more complicated to dynamically load a WebControl with PartialCaching. I did not try it, but I take it for granted that...
9
by: Mike | last post by:
Hi, Just a simple question: why the compiler doesn't report error when accessing a private member function inside a function having template type ? For example: #include<iostream> using...
2
by: MikhailGorbachev | last post by:
I'm having a problem getting derived types to be inferred as valid parameters by a function template. template <typename T> struct Base {} template<typename T> struct Derived : public...
8
by: Ralf Goertz | last post by:
Hi, I want to do able to declare an object bar of a templated class foo where the actual template type of foo is only know at runtime: ----- #include <string> template <class Tclass foo {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.