![]() |
Properties for User Controls loaded Programmatically
I have x number of user controls that have a strong type (e.g.
className uc1). I am able to access their properties through a single aspx page using: uc = LoadControl(path to control based on querystring value) textbox.Text = CType(uc, uc1).someproperty The thing I need to do though is to specify the type (e.g. uc1) on the fly based on the path created for that user control. For example (ignoring declarations): path = "path to user control directory" 'For each valid ucid there is a strong type associated with the 'user control using className in the ascx page. ucid = request.querystring("ucid") uc = LoadControl(path & ucid) 'Add the user control to the page placeholder.Controls.Add(uc) This is where I am stuck... I need to access the properties of the control based on the ucid. When I hard code it I use CType and specify the user control className. But in this case I do not know which user control will be called as it depends on the ucid (all the user controls have the same properties). There may 20-30 user controls and I would hate to have to hard code each of the possibilities. Ultimately I am looking for something like this: path = "path to user control directory" ucid = request.querystring("ucid") uc = LoadControl(path & ucid) placeholder.Controls.Add(uc) textbox.text = uc.someproperty Thx for any help or direction! Tom |
Re: Properties for User Controls loaded Programmatically
TK, are you using vs.net or are you coding this in a tool like web matrix or
just plain note pad. Thing is, if your using web matrix or note pad, the approaches these tools use is spaghetti code that is a combination of the presentation with code. Vs.net makes it easier to seperate your code from your presentation by using a concept which you might have already heard of "Codebehind" classes. The reason i'm telling you this is because some of the sample code on msdn/gotdotnet/docs assume you are not using vs.net for your development and provide you with sample as to how to achieve your goals using the spaghetti code approach. This is why on the example code you are seeing it reads "'For each valid ucid there is a strong type associated with the user control using className in the ascx page." and if you are coding using code behind classes then you do not have to bother with this --clarify this for me and what it is you want to do i'll provide you with the help you need ;P "TK" <tklawsuc@hotmail.com> wrote in message news:9c5a156d.0402241111.4c17ef46@posting.google.c om... > I have x number of user controls that have a strong type (e.g. > className uc1). I am able to access their properties through a single > aspx page using: > > uc = LoadControl(path to control based on querystring value) > textbox.Text = CType(uc, uc1).someproperty > > The thing I need to do though is to specify the type (e.g. uc1) on the > fly based on the path created for that user control. For example > (ignoring declarations): > > path = "path to user control directory" > > 'For each valid ucid there is a strong type associated with the > 'user control using className in the ascx page. > ucid = request.querystring("ucid") > > uc = LoadControl(path & ucid) > > 'Add the user control to the page > placeholder.Controls.Add(uc) > > This is where I am stuck... > I need to access the properties of the control based on the ucid. > When I hard code it I use CType and specify the user control > className. > But in this case I do not know which user control will be called as it > depends on the ucid (all the user controls have the same properties). > There may 20-30 user controls and I would hate to have to hard code > each of the possibilities. > > Ultimately I am looking for something like this: > > path = "path to user control directory" > ucid = request.querystring("ucid") > uc = LoadControl(path & ucid) > placeholder.Controls.Add(uc) > textbox.text = uc.someproperty > > > Thx for any help or direction! > > Tom |
Re: Properties for User Controls loaded Programmatically
I got stuck on the line where you stated "'For each valid ucid there is a
strong type associated with the user control using className in the ascx page" doh! Now that i re-read your post, i think, i get where your getting at. You will have to use a lot of if statements and conditionally check if its of that specific type and then perform your needs. Look at the sample code below : uc = LoadControl(path to control based on querystring value) If TypeOf uc Is UC1 Then textbox.Text = CType(uc, uc1).someproperty elseif TypeOf uc Is UC2 Then textbox.Text = CType(uc, uc2).someproperty 'more conditions .... End if ....etc "Alessandro Zifiglio" <alessandrozifiglio@NO-SPAM-hotmail.com> wrote in message news:npm%b.11906$HO2.853@news.edisontel.com... > TK, are you using vs.net or are you coding this in a tool like web matrix or > just plain note pad. Thing is, if your using web matrix or note pad, the > approaches these tools use is spaghetti code that is a combination of the > presentation with code. Vs.net makes it easier to seperate your code from > your presentation by using a concept which you might have already heard of > "Codebehind" classes. The reason i'm telling you this is because some of the > sample code on msdn/gotdotnet/docs assume you are not using vs.net for your > development and provide you with sample as to how to achieve your goals > using the spaghetti code approach. This is why on the example code you are > seeing it reads "'For each valid ucid there is a strong type associated with > the user control using className in the ascx page." and if you are coding > using code behind classes then you do not have to bother with this --clarify > this for me and what it is you want to do i'll provide you with the help you > need ;P > > > > > "TK" <tklawsuc@hotmail.com> wrote in message > news:9c5a156d.0402241111.4c17ef46@posting.google.c om... > > I have x number of user controls that have a strong type (e.g. > > className uc1). I am able to access their properties through a single > > aspx page using: > > > > uc = LoadControl(path to control based on querystring value) > > textbox.Text = CType(uc, uc1).someproperty > > > > The thing I need to do though is to specify the type (e.g. uc1) on the > > fly based on the path created for that user control. For example > > (ignoring declarations): > > > > path = "path to user control directory" > > > > 'For each valid ucid there is a strong type associated with the > > 'user control using className in the ascx page. > > ucid = request.querystring("ucid") > > > > uc = LoadControl(path & ucid) > > > > 'Add the user control to the page > > placeholder.Controls.Add(uc) > > > > This is where I am stuck... > > I need to access the properties of the control based on the ucid. > > When I hard code it I use CType and specify the user control > > className. > > But in this case I do not know which user control will be called as it > > depends on the ucid (all the user controls have the same properties). > > There may 20-30 user controls and I would hate to have to hard code > > each of the possibilities. > > > > Ultimately I am looking for something like this: > > > > path = "path to user control directory" > > ucid = request.querystring("ucid") > > uc = LoadControl(path & ucid) > > placeholder.Controls.Add(uc) > > textbox.text = uc.someproperty > > > > > > Thx for any help or direction! > > > > Tom > > |
| All times are GMT. The time now is 12:51 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.