Loading controls

A

Amir Ghezelbash

Can somebody show me how to load a control that has properties
programmically... in asp.net 2.0 i know how to do it in asp.net 1.1 but
asp.net 2.0 uses partial classes so casting doesnot take in effect
....what can i do ?

thank you in advance !
 
S

Scott Allen

The partial keyword should not change how you cast an object
reference, can you show us the code you are trying to use?
 
A

Amir Ghezelbash

Control ctlControl=null;
ctlControl = LoadControl("FeaturedProduct1.ascx");
((FeaturedProduct1)ctlControl).BackColor = "Yellow";

this casting doesnot work in asp.net 2.0 ...why ?
 
S

Scott Allen

Hi Amir:

When you say it does not work do you mean there is a compilation error
or a run time exception?

Can you post FeaturedProduct1.ascx and .cs?

I've tried similar code without a problem, so I'm not sure where the
problem could be...
 
A

Amir Ghezelbash

Hi sorry for the late response
the error i am getting is that it cant find the class to cast

the code i am using is
Control c1 =
LoadControl("~/Controls/MemberPageControls/Uploader/Email/DBUploader.asc
x");
((DBUploader)c1).CurrentCampaign = null;
PlaceHolder1.Controls.Add(c1);


i tried to put the cs code behind the ascx file into a namespace then
import that namespace but that gives me this error...any body any
idea..it would work if the aspx file is in the same dir as the actual
control i am trying to load up

the error===>

Error 4 'ASP.Hello.FrameworkInitialize()': no suitable method found to
override c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\Temporary ASP.NET
Files\website3\33dec574\6f269059\nhfoxkh2.0.cs 136
 
S

Scott Allen

Hi sorry for the late response
the error i am getting is that it cant find the class to cast

the code i am using is
Control c1 =
LoadControl("~/Controls/MemberPageControls/Uploader/Email/DBUploader.asc
x");
((DBUploader)c1).CurrentCampaign = null;
PlaceHolder1.Controls.Add(c1);

Hi amir:

I'm on the same page now. The problem is this confusing compliation
model in ASP.NET 2.0.

Where does the above code reside? In a file in /App_Code or in the
code-behind for a web form?

If you are writing this in the code behind for a webform, you should
be able to add a VirtualPath in a @ Reference directive. See:

http://odetocode.com/Blogs/scott/archive/2005/06/30/1889.aspx

If you are not inside a webform - it gets a lot tricker....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top