CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: Date Entered: 7/5/2005 7:50:42 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 4 Views: 175 Favorited: 0 Favorite
5 Items, 1 Pages 1 |< << Go >> >|
"bben" <>
NewsGroup User
Load Control from given string type7/5/2005 7:50:42 AM

0

Hello Everyone ,
I 've built a custom server control in ASP.NET 1.1 : a simple TreeView. I'm using this treeview in an aspx page like this:
<cc1:tree id="id1" text="text1">
   <cc1:tree id="id2" text="text2">
      <cc1:tree id="id3" text="text3">
         <asp:textbox id="tb1" text="txt"/>
      </cc1:tree>
   </cc1:tree>
</cc1:tree>

It's a recursive control. I want to be able to add any control inside (a native ASP.NET control as TextBox or another server control That I've built to)

To be able to parse sub xml tags, I 've create a specific Builder inheriting from ControlBuilder
I Don't want to make a big switch case to tell to my builder : "if tag contains "textbox" word return System.Web.UI.WebControls.TextBox and so on...
Is it possible in code behind to load controls from their tag name ?
Is it possible to access to registred assemblies of the page ?
I'm asking theses questions because I want to make a call like this : GetType (    assembly_name + xm_ltag_name )...

Thanks in advance

bben


 

"billrob458" <>
NewsGroup User
Re: Load Control from given string type7/5/2005 2:56:07 PM

0

You can create controls by their tag name.  The method uses reflection, which isn't the cheapest .net functionality around.  However if this code is in your ControlBuilder, it will only be reflected on the first time the .aspx is compiled, versus in the Page_Load where the reflection code with run every page hit.

//there are probably 15 different ways to do this.
TextBox box = ( TextBox ) Activator.CreateInstance( Type.GetType( "System.Web.UI.WebControls.TextBox, System.Web" ) );

parentControl.Controls.Add( box );

I don't know what you mean by "registered assemblies of the page."

bill
"joteke" <>
NewsGroup User
Re: Load Control from given string type7/5/2005 3:10:46 PM

0

There's also Page.ParseControl method which is able to take a string (declarative as ASPX syntax, with custom controls should contain the < %@reference  % > directive at beginning of it so that it knows from where to parse them) and create control instance out of it. It can handle multiple (nested) controls at once too.
Thanks,

Teemu Keiski
Finland, EU
"bben" <>
NewsGroup User
Re: Load Control from given string type7/6/2005 7:24:02 AM

0

Thanks guys for you replies

I meant by "registred assemblies  " assemblies that you found at the begining of aspx pages like
<%@ Register TagPrefix="cc1" Assembly="AssemblyName" NameSpace="MyNameSpace  %>

I'm kind of stuck , didn't succeed in using ParseControl correctly. Moreover I'm in ControlBuilder class, so I don't have access to Page.ParseControl

Thanks
"Eilon" <>
NewsGroup User
Re: Load Control from given string type7/7/2005 4:34:04 AM

0

Hi,
Since you're writing your own ControlBuilder, why not just call base.GetChildControlType(), where tagName is the tag's name, such as "asp:TextBox" and the attributes is a dictionary of the attributes on the tag. I do not recommend manually calling Type.GetType() because you won't be able to map all the tags to appropriate namespaces, etc. and you'll definitely fail if the tag is a UserControl.

Though, even aside from all this, why do you need to write your own ControlBuilder? ASP.net already knows how to add child controls to a parent control. As long as you have ParseChildren(false) on your control, the right thing should happen without the need for a ControlBuilder.

Thanks,
Eilon


Blog: http://weblogs.asp.net/LeftSlipper/
5 Items, 1 Pages 1 |< << Go >> >|


Free Download:













adding dropdown list to properties window

custom server control subclassed from panel not working correctly at design time

composite control with datalist

composite vs rendering controls

creating a new control

has the tagprefix attribute for custom web controls changed for 2.0 ?

problem with datagrid checkbox column checkedchange event

getting treeview to postback when node is checked/unchecked

js error in tree view web control.

added child control is not rendered

'[propertyname]' could not be initialized.

is there any attribute to indicate required property?

reference problem. bc30002: type '' is not defined.

re-using "selectedindexchanged" for multiple controls

inheriting from textbox

click event on panel

2nd attempt - license an asp.net server control (dll)

control panel graphics

creating a modified panel control?

hosting web sites on home computer

reliablesite.net - has baddest support i ever seen

problems binding data to a user control?

progress bar with httphandler

finding a hosting package

the custom control works fine, but hard to work with in vs 2003 design mode

problems creating a personal design time layout for my control

raising event in custom control

plz advise: max $20

custom designers

custom textboxes and validator control

how do i programmatically set the item template of a datalist ?

submit button in user control , usercontrol in placeholder

single style declaration for multiple control instances

asp 2.0 callback and viewstate/controlstate

problems with using a datagrid in custom server control

stuck without multiple inheritance

custom control or composite control ?

how can i reference a public function in parent form from a child web control

disabling validation in a custom control

composite controls

getting name of control which generated postback

maintaining viewstate on dropdown menu

alternate method to attachevent

building datagrid...

drag and drop within ie

please help hosting problems.

question about changing custom control events

control properties defined procedurally

requiredcheckboxlistvalidator

serlializing properties of user controls.

   
  Privacy | Contact Us
All Times Are GMT