Re: CompositeControl fails to display in Design view
- From: MC <mc@xxxxxxxxxxxxxxxx>
- Date: Thu, 11 Oct 2007 21:10:22 GMT
I've tried to simplify the problem and have removed all functionality from the code other than a stock adRotator (see code Below) and I still get the error. I also get the error with just a SqlDataSource as well.
public class Test : CompositeControl
{
protected override void CreateChildControls()
{
AdRotator ar = new AdRotator();
Controls.Add(ar);
}
}
However my other control Test2 works fine
public class Test2 : CompositeControl
{
protected override void CreateChildControls()
{
Label lbl = new Label();
lbl.Text = "Test Label";
Controls.Add(lbl);
TextBox tb = new TextBox();
Controls.Add(tb);
}
}
Philvb wrote:
Hi MC,.
one thing that i have notice is that even at design time you add a handler for the ADCreated, i'm not sure this handler will work due to it not being just markup, try reformatting it like:
If (DesignMode == False) {adRot.AdCreated += new AdCreatedEventHandler(this_AdCreated)}
Not sure i wrote that correctly as i write VB, but i'm sure you get the meaning.
Phil
"MC" wrote:
I think I've followed your instructions however I get no exceptions.
I have an empty site
I set the debug to run devenv.exe (vs2005)
It Loads my project fine
I then view the page with the broken control on it and nothing happens?
am I doing something wrong?
MC wrote:apologies, should have read your description in more detail
Philvb wrote:Hi MC,
Yes, if you follow the instructions then that is how you can debug the designer.
Phil
"MC" wrote:
I have no problem with the Custom Control, It works fine in the browser, It is the design time experience that is not working.
Can you debug the designer in Visual Studio?
Philvb wrote:Hi MC,
the message you are getting here is from your logic in the rendering of the control at a guess i'd say that an object hasn't been instanciated.
But here's how i debug ALL my custom controls in real time.
In Order to debug a Custom Control you need to Start ANOTHER copy of Visual Studio along side your existing one,and pointing it to a test website.
This can be done by
Going To The Controls Project Properties and Selecting The Debug Tab then set the start action to `Start External Program` and set the box next to it to the location of devenv.exe from the correct folder of program files.
i am using orcas beta2 here and this path is: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe
Now set the Command Line Arguments to: /Command File.OpenWebsite TheTestingWebSite.sln
Now The Final Step Is To Enter The FULL Path of Your SOLUTION FILE in the Working Directory text box.
Just press F5 to start your debugging Adventure...
hope this helps
Wbr
Phil
"MC" wrote:
I'm getting the following error messages when I view my ComposisteControl in design time mode.
"Error Rendering Control - <My Control Name>"
"An unhandled exception has occurred
Object reference not set to an instance of an object"
The Control is as follows: -
public class TrackedAd : CompositeControl
{
public SqlDataSource sdsAds = new SqlDataSource();
public System.Web.UI.WebControls.AdRotator adRot = new System.Web.UI.WebControls.AdRotator();
private string _Target = "_blank";
private int _SponsorId = -1;
[Description("The Browser Target for the Attribute"), TypeConverterAttribute(typeof(TargetConverter))]
public string Target
{
get { return _Target; }
set { _Target = value; }
}
public int SponsorId
{
get { return _SponsorId; }
set { _SponsorId = value; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.RegisterRequiresControlState(this);
}
protected override object SaveControlState()
{
object[] state = { base.SaveControlState(), _Target, _SponsorId };
return state;
}
protected override void LoadControlState(object state)
{
if (state != null)
{
object[] stateTmp = (object[])state;
base.LoadControlState(stateTmp[0]);
_Target = (string)stateTmp[1];
_SponsorId = (int)stateTmp[2];
}
}
protected override void CreateChildControls()
{
sdsAds.ConnectionString = ConfigurationManager.ConnectionStrings["RedsSponsors"].ConnectionString;
sdsAds.ProviderName = ConfigurationManager.ConnectionStrings["RedsSponsors"].ProviderName;
sdsAds.SelectCommand = string.Format("SELECT '{0}'+iif(ImageName<>null,ImageName,'../transp.gif') AS ImageUrl, CompanyName AS AlternateText, URL AS NavigateUrl, Impressions, Clicks FROM Sponsors WHERE Id={1}", Utils.SponsorsImageBase, SponsorId);
sdsAds.ID = "sdsAds";
adRot.AdCreated += new AdCreatedEventHandler(this_AdCreated);
adRot.DataSourceID = "sdsAds";
adRot.Target = Target;
Controls.Add(sdsAds);
Controls.Add(adRot);
}
protected void this_AdCreated(object sender, AdCreatedEventArgs e)
{
SponsorsUtils.IncrementAdvertStat("CompanyName", "Impressions", e.AlternateText);
if (e.NavigateUrl != "")
{
e.NavigateUrl = string.Format("~/Adverts/AdvertHandler.ashx?Url={0}", Page.Server.UrlEncode(e.NavigateUrl));
}
}
}
What is wrong? I thought by using compositecontrol I would not have to worry about designtime?
- Follow-Ups:
- Re: CompositeControl fails to display in Design view
- From: Steven Cheng[MSFT]
- Re: CompositeControl fails to display in Design view
- References:
- CompositeControl fails to display in Design view
- From: MC
- RE: CompositeControl fails to display in Design view
- From: Philvb
- Re: CompositeControl fails to display in Design view
- From: MC
- Re: CompositeControl fails to display in Design view
- From: Philvb
- Re: CompositeControl fails to display in Design view
- From: MC
- Re: CompositeControl fails to display in Design view
- From: MC
- Re: CompositeControl fails to display in Design view
- From: Philvb
- CompositeControl fails to display in Design view
- Prev by Date: Re: CompositeControl fails to display in Design view
- Next by Date: RE: Https errors in IE7 for WebResouce requests.
- Previous by thread: Re: CompositeControl fails to display in Design view
- Next by thread: Re: CompositeControl fails to display in Design view
- Index(es):
Relevant Pages
|