A
Alan Silver
Hello,
I have a user control that has one .cs file, with several .ascx files
that call it. The reason for this is that I can pick whichever of the
..ascx files I want (based on a site owner setting), and I know the
code-behind is the same in all cases. That way the .ascx file can be
picked dynamically, allowing the appearance of the page to be changed
based on a user setting.
This was working fine in 1.1, but had the code-behind compiled into a
DLL. I'm trying to convert the user control(s) to use the new 2.0
code-behind model, and would like to avoid having to compile the DLL
each time.
The page that uses the control has a placeholder called
plcProductDetails, and has code like...
string fileName = "ShowProductStyle1.ascx"; // normally from user
setting
Control ctlShowProduct = LoadControl(fileName);
((ShowProduct)ctlShowProduct).DisplayProduct();
plcProductDetails.Controls.Add(ctlShowProduct);
Now this worked fine when using the old 1.1 code-behind model. I could
compile ShowProduct.dll on its own and the code above would find it OK.
Now I have deleted the DLL, and changed the top of each of the .ascx
files to look like...
<%@ Control CodeFile="ShowProduct.cs" Inherits="ShowProduct" %>
and the top of the code-behind file looks like...
// various "using" statements omitted for clarity
public partial class ShowProduct : UserControl {
If I try to load the page now, I get an error...
"CS0246: The type or namespace name 'ShowProduct' could not be found"
on the line...
((ShowProduct)ctlShowProduct).DisplayProduct();
I don't know how to get around this. When LoadControl was called, it
referenced the .ascx file, and that referenced the code-behind file that
contains the class definition for ShowProduct. Why then can't the
framework find the class?
I hope this is clear. I'm really lost here and would appreciate any clue
as to how I am supposed to do this. The weird thing is that I tried
creating a user control in VWD, and I could have two .ascx files
referencing the same .cs file and they both work fine without me needing
to compile anything. I'm obviously doing something wrong, but I can't
see what.
TIA
I have a user control that has one .cs file, with several .ascx files
that call it. The reason for this is that I can pick whichever of the
..ascx files I want (based on a site owner setting), and I know the
code-behind is the same in all cases. That way the .ascx file can be
picked dynamically, allowing the appearance of the page to be changed
based on a user setting.
This was working fine in 1.1, but had the code-behind compiled into a
DLL. I'm trying to convert the user control(s) to use the new 2.0
code-behind model, and would like to avoid having to compile the DLL
each time.
The page that uses the control has a placeholder called
plcProductDetails, and has code like...
string fileName = "ShowProductStyle1.ascx"; // normally from user
setting
Control ctlShowProduct = LoadControl(fileName);
((ShowProduct)ctlShowProduct).DisplayProduct();
plcProductDetails.Controls.Add(ctlShowProduct);
Now this worked fine when using the old 1.1 code-behind model. I could
compile ShowProduct.dll on its own and the code above would find it OK.
Now I have deleted the DLL, and changed the top of each of the .ascx
files to look like...
<%@ Control CodeFile="ShowProduct.cs" Inherits="ShowProduct" %>
and the top of the code-behind file looks like...
// various "using" statements omitted for clarity
public partial class ShowProduct : UserControl {
If I try to load the page now, I get an error...
"CS0246: The type or namespace name 'ShowProduct' could not be found"
on the line...
((ShowProduct)ctlShowProduct).DisplayProduct();
I don't know how to get around this. When LoadControl was called, it
referenced the .ascx file, and that referenced the code-behind file that
contains the class definition for ShowProduct. Why then can't the
framework find the class?
I hope this is clear. I'm really lost here and would appreciate any clue
as to how I am supposed to do this. The weird thing is that I tried
creating a user control in VWD, and I could have two .ascx files
referencing the same .cs file and they both work fine without me needing
to compile anything. I'm obviously doing something wrong, but I can't
see what.
TIA