CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 7/16/2003 5:36:41 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 9 Views: 63 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
10 Items, 1 Pages 1 |< << Go >> >|
jimbuuck
Asp.Net User
Programmatically adding/removing controls at design time7/16/2003 5:36:41 PM

0/0

I am looking for a way (from my custom web control designer) to programmatically add (or remove) an ASP.NET control to a web form at design time.

I can use IDesignerHost.CreateComponent (or IDesignerHost.DestroyComponent) to add (or remove) a non-visual component to the web form from my designer, but when I try to do it with a visual control it adds the declaration to the code-behind page, but does not add the control to the .aspx page.

Am I doing something wrong or is there another way to do this? Here is a simple example that just tries to add a Label control when MyControl is added to a web form. Any help is much appreciated.
// MyControl.cs

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

namespace TestControls
{
[ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]
[Designer(typeof(MyControlDesigner))]
public class MyControl : Label
{
}

public class MyControlDesigner : System.Web.UI.Design.WebControls.LabelDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);

IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if (host != null)
{
if (!host.Loading)
{
Label label = AddNewLabelComponent();
}
}
}

private Label AddNewLabelComponent()
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
Label label;

using (DesignerTransaction trans =
host.CreateTransaction("Creating new Label"))
{
label = (Label)host.CreateComponent(typeof(Label));
trans.Commit();
}
return(label);
}
}
}

Jim
autofed
Asp.Net User
Re: Programmatically adding/removing controls at design time7/20/2003 9:15:22 PM

0/0

You create the label, but you never add it to the page control hierarchy. If all you're trying to do is add a regular label server control, you can just use something like the following:


Label myLabel = new Label();
Controls.Add(myLabel);


My apologies if I have misunderstood what you're trying to do. If you can clarify I will try again.

AutoFed
jimbuuck
Asp.Net User
Re: Programmatically adding/removing controls at design time7/21/2003 6:03:03 AM

0/0

Thanks for the reply, but what you're talking about is how I would add a Label to the page at runtime. I'm trying to add the Label to the page at design-time which means it gets persisted into the .aspx file. Note that I am doing the IDesignerHost.CreateComponent from the designer of my custom control.

The approach I described works if I were trying to add a non-visual component (like OleDbDataAdapter) to the code-behind page (.aspx.cs), but doesn't seem to work for adding visual controls (like Label) to the page (.aspx). So I'm wondering if IDesignerHost.CreateComponent is only supposed to work for non-visual components and perhaps there's a different API for adding visual components at design-time.

Jim
simoncal
Asp.Net User
Re: Programmatically adding/removing controls at design time7/21/2003 8:09:15 PM

0/0

Yes, this is for a non-visual component

You could simply modify your ToolboxData string to include the string representing the Control you want to add in. Of course this limits the location of the associated control to bfore or after the tag for the 'parent'.

There is a mechanism to obtain the DesignTimeElement, which is an IHtmlElement, and then use the MSHTML interfaces and properties to eventually insert a tag at the appropriate point in the tree. I'm not sure that this is a fully supported scenario in Visual Studio however.

Let me know if you need more details...
Simon
This posting is provided "AS IS" with no warranties, and confers no rights.
jimbuuck
Asp.Net User
Re: Programmatically adding/removing controls at design time7/22/2003 6:48:34 PM

0/0

I tried including the string representing the Control in my ToolboxData string and it would work great except that I don't want to add the Control everytime one of my custom controls is added - just the first time.

So I'm looking into your second alternative. The IHtmlElement interface definition does not appear to be a standard part of the .NET Framework. How do I get the IHtmlElement interface definition so I can compile with it? Will I be able to call insertAdjacentHTML on the interface, or is there some other way I should go about adding my control?

Thanks for you help.
Jim
stevebohere
Asp.Net User
Re: Programmatically adding/removing controls at design time10/4/2004 2:56:40 PM

0/0

Jim, did you ever get this solved? I'm working on the same exact problem right now and I can't seem to find anything that will help very much.
jimbuuck
Asp.Net User
Re: Programmatically adding/removing controls at design time10/4/2004 5:58:26 PM

0/0

No. I ended up not trying to automatically add the control.
Sundance Kid
Asp.Net User
Re: Programmatically adding/removing controls at design time1/6/2005 6:26:59 AM

0/0

Did anyone get it working. I have the EXACT Same problem now.

or any pointers?
AndrewSeven
Asp.Net User
Re: Programmatically adding/removing controls at design time1/11/2005 2:18:03 AM

0/0

Using MSHTML.IHTMLElement:

The method below is called within my designer, the control being added is added as a child control. The parent and child are from the same namespace (thus scopeName)

IHTMLElement gives you access to the DOM of the design surface but will be obsolete in .Net 2.0


For a simple example that uses mshtml: http://weblogs.asp.net/andrewseven/articles/DesignTimeViewAsText.aspx


private void AddContentContainer(string controlID)
{
IHTMLElement copy = ((mshtml.IHTMLElement)this.DesignTimeElement);
string controlNS = ((mshtml.IHTMLElement2)this.DesignTimeElement).scopeName;
Utilities.MsgBox("AddContentContainer scopeName" + controlNS);

string source = "<{0}:ContentContainer id=\"" + controlID + "\" runat=\"server\" >Added Content Container for: {1}</{0}:ContentContainer>";
copy.innerHTML += string.Format(source,controlNS,controlID);

}
stevebohere
Asp.Net User
Re: Programmatically adding/removing controls at design time1/11/2005 5:29:52 PM

0/0

Nice job bro. I've been messing with VS.NET 2005 designers. Do you know of any good links to better help me out? Are there going to be any books out soon?
10 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Microsoft Visual C# .NET 2003 Developer's Cookbook: Developer's Cookbook Authors: Mark Schmidt, Simon Robinson, Pages: 787, Published: 2003
Developing Web Applications with Visual Basic.NET and ASP.NET Authors: John Alexander, Billy Hollis, Pages: 400, Published: 2002
ASP.NET 2.0 All-In-One Desk Reference For Dummies: all-in-one desk reference for dummies Authors: Doug Lowe, Jeff Cogswell, Ken Cox, Pages: 910, Published: 2006
Programming ASP.NET: Building Web Applications and Services with ASP.NET 2.0 Authors: Jesse Liberty, Dan Hurwitz, Pages: 930, Published: 2005
Excel 2007 Power Programming with VBA Authors: John Walkenbach, Pages: 1061, Published: 2007
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages Authors: Jacob J. Sanford, Pages: 474, Published: 2007
ASP. Net Development with Dreamweaver Mx: Ryan Parnell, Joel Martinez Authors: Ryan Parnell, Joel Martinez, Pages: 320, Published: 2002
Pro ASP.NET 2.0 in VB 2005: special edition. Authors: Laurence Moroney, Matthew MacDonald, Pages: 1360, Published: 2006
Visual Basic.NET Unleashed Authors: Paul Kimmel, Pages: 784, Published: 2002

Web:
Programmatically adding/removing controls at design time - ASP.NET ... Programmatically adding/removing controls at design time. Last post 01-11-2005 12:39 PM by stevebohere. 9 replies. Sort Posts: ...
Adding Controls to Office Documents at Run Time Controls that you add at design time are also called static controls. ... Do not programmatically remove controls in the Shutdown event handler of the ...
book microsoft visual c# .net 2003 developer's cookbook, other ... Changing a Control's Toolbox Icon. Programmatically Adding Controls to the Toolbox. ... Extending the Design Time Context Menu. Removing Control Properties ...
Safari Books Online - 0672325802 - Microsoft® Visual C#® .NET 2003 ... Extending the Design Time Context Menu · Removing Control Properties Using ... User Controls > Programmatically Adding Controls to the Toolbox. Preview ...
Adding to or Removing from a Collection of Controls at Run Time At design time, controls can be dragged directly onto a panel or group box. ... To remove controls from a collection programmatically ...
Brian Dao's Blog: Programmatically Add Controls At Runtime As I have experienced it, in some situations, you might not know the types of control or how many controls will be needed at design time. ...
vbCity/DevCity.NET Forums :: .NET :: VB.NET :: programmatically ... This particular control doesn't have any design time layout requirements. ... This step of adding and deleting the control causes . ...
CodeProject: Programmatically adding attachments to emails. Free ... A technique for programmatically adding attachments to emails.; ... Many was the time I have needed a way to send an application's document to another user. ...
HowTo: Can't programmatically change control properties at design ... HowTo: Can't programmatically change control properties at design time. Last post 01-03-2007 1:05 AM by jbowman. 5 replies. Sort Posts: ...
O'Reilly - Safari Books Online - 0672325802 - Microsoft® Visual C# ... Programmatically Adding Controls to the Toolbox ... Listing 9.3. Properties of a Control with Design-Time Attributes ...

Videos:
Developing JavaScript with Chickenfoot Google TechTalks July 25, 2006 Rob Miller Michael Bolin ABSTRACT Chickenfoot is a Firefox extension that embeds a JavaScript programming environmen...




Search This Site:










asp array /asp.net arry diffrences

login failed for user 'dotnetnuke'. reason: not associated with a trusted sql server connection.

how to flush just the contents of a master page?

can't change module container on site (dnn 4.0)

same user names for a child subportal

how to get hyperlinks work in a stringbuilder????

returns nothing directory.getfiles("c:\", "*.*")

feedback: resellerschoice hosting (dropping tacticalsystems)

client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'

the building process

vs 2005 app code compilation

call functions from contentpages

working with sourcesafe

firefox compatibility with login controls

memeber locked out

dnn 2.0 skinning whitepaper sample skin template ?

css doesnt affect immediately

how do i change the access denied module title?

.net and ichain

images of custom modules with a . (dot) in foldername

problems with web controls

security exception when trying to deserialze/serialize a memorystream

web.config problem

site samples

sortable gridview in webpart

passing a very long string to another page - javascript

gooddogs repository module source code now available

derived classes, datagrid, vb.net

url rewriting security pitfalls

page callbacks

 
All Times Are GMT