Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Maria Silva   on Aug 14 In Asp.net Category.

  
Question Answered By: Mildred Bailey   on Aug 14

This is a note in answer  to my previously posted question - sent for tips incase anyone comes across the 'problem' in future.

It's not a problem, it was me. The LoadControl DOES actually mean Load the ascx.

If you want to create controls  entirely in code then DO NOT use System.Web.UI.UserControl
(I was sure that I had overidden Render in UserControl in a previous occasion, but I can't seem to do it now even though the docs tell me I should be able to)

Use a System.Web.UI.WebControls.WebControl and overidding Render is easy.

Notes :: If you don't want to overide render in one of these things but wish merely to add  controls to it then use this set up ::


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace cntrls
{
/// <summary>
/// Summary description for cc.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:cc runat=server></{0}:cc>")]
public class cc : System.Web.UI.WebControls.WebControl
{
private string text;
protected System.Web.UI.WebControls.Label L1;

[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}

/// <summary>
/// Render this control  to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
// protected override void Render(HtmlTextWriter output)
// {
// output.Write(Text);
// }
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
L1 = new Label();
L1.Text = "hello from CC3";
this.Controls.Add(L1);

}
}
}


Other worthy notes ::

Its easy to include controls of the same type simply by instantiating them (obviously adding UserControls ith ascx  files defeates the object as you can't wrap the whole thing nicely in a dll - if indeed it's even possible (possibly ?? I don't even care and ain't bothering to find out))

ALSO NOTE :: When rebuilding and adding/subracting controls I found that sometimes - although I had added them to the toolbox, etc ... that the extra ones were not being allowed to be dragged to the aspx page.
Solution was to dereference the library and then reference it. Done.

Also - VS.NET has 'em all stuck in mem (or somewhere) and they're a bugger to get rid of - just reset the toolbox between attempts.


I now have everything I need to make controls available to the toolbox.

Share: 

 
 
Didn't find what you were looking for? Find more on LoadControl Or get search suggestion and latest updates.


Tagged: