|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
(Hard one,any expert out threre ? ) Create object from string ? add webcontrols dynamically on page.I have some webcontrols that i want to add dynamically on a page. I have stored the path / namespace in database (ex MyNameSpace.WebControls.Control1) to the class/webcontrol. Lets say i have a column in database that looks like this. PageID (int) Webcontrol (varchar) 1 MyNameSpace.WebControls.Control1 1 MyNameSpace.WebControls.Control2 Then i want to add the controls dynamically on the page, anyone know how to do this ? I guess i have to create a instance of the webcontrol and the add it with Controls.add() . But how do i create the instance and add it dynamically from a string? Hope anyone can help me with this, some expert out there ?? :) Thanks Jesper <jesper_lofg***@yahoo.se> wrote in message
Show quote news:1134846255.304681.258640@g14g2000cwa.googlegroups.com... I am not an expert, just beginning but it you might consider placing> Hi there, > > I have some webcontrols that i want to add dynamically on a page. I > have stored the path / namespace in database (ex > MyNameSpace.WebControls.Control1) to the class/webcontrol. > > Lets say i have a column in database that looks like this. > > PageID (int) Webcontrol (varchar) > 1 MyNameSpace.WebControls.Control1 > 1 MyNameSpace.WebControls.Control2 > > Then i want to add the controls dynamically on the page, anyone know > how to do this ? > I guess i have to create a instance of the webcontrol and the add it > with Controls.add() . But how do i create the instance and add it > dynamically from a string? > > Hope anyone can help me with this, some expert out there ?? :) > the controls on the webform in design mode with the visible property set to false, then at runtime simple set the visible property to true as needed. Mike ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- It's much easier if you have the path. Controls are templated and aren't
instantiated like normal classes. Control c = Page.LoadControl("~/controls/login.ascx"); container.Controls.Add(c); Karl -- Show quoteMY ASP.Net tutorials http://www.openmymind.net/ http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX! <jesper_lofg***@yahoo.se> wrote in message news:1134846255.304681.258640@g14g2000cwa.googlegroups.com... > Hi there, > > I have some webcontrols that i want to add dynamically on a page. I > have stored the path / namespace in database (ex > MyNameSpace.WebControls.Control1) to the class/webcontrol. > > Lets say i have a column in database that looks like this. > > PageID (int) Webcontrol (varchar) > 1 MyNameSpace.WebControls.Control1 > 1 MyNameSpace.WebControls.Control2 > > Then i want to add the controls dynamically on the page, anyone know > how to do this ? > I guess i have to create a instance of the webcontrol and the add it > with Controls.add() . But how do i create the instance and add it > dynamically from a string? > > Hope anyone can help me with this, some expert out there ?? :) > > Thanks > Jesper > Assuming that there is some good reason for using a database to dynamically
load controls, I think you've gotten off on the wrong foot. Why are you storing strings in the database? The names of namespaces and classes is useful to us humans, but not particularly to computers. It would be more efficient to store integers in the database. Assuming (again) that you know what you're storing in the database, you could create Enumerations that represent different namespaces and classes, and store the enumerated values in the database. From there it's a simple matter of identifying the Control to load via its enumerated value. You would need some sort of mechanism to identify the Controls whose names are stored in the database anyway. You could do it with Reflection, but that would be expensive, and I see no benefit gained from it. -- Show quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer You can lead a fish to a bicycle, but it takes a very long time, and the bicycle has to *want* to change. <jesper_lofg***@yahoo.se> wrote in message news:1134846255.304681.258640@g14g2000cwa.googlegroups.com... > Hi there, > > I have some webcontrols that i want to add dynamically on a page. I > have stored the path / namespace in database (ex > MyNameSpace.WebControls.Control1) to the class/webcontrol. > > Lets say i have a column in database that looks like this. > > PageID (int) Webcontrol (varchar) > 1 MyNameSpace.WebControls.Control1 > 1 MyNameSpace.WebControls.Control2 > > Then i want to add the controls dynamically on the page, anyone know > how to do this ? > I guess i have to create a instance of the webcontrol and the add it > with Controls.add() . But how do i create the instance and add it > dynamically from a string? > > Hope anyone can help me with this, some expert out there ?? :) > > Thanks > Jesper >
Other interesting topics
|
|||||||||||||||||||||||