Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

type cast issue

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
I got this straight from MS

Code:
<%@ Reference Control=&quot;MyUserControl.ascx&quot; %>

Dim c1 As UserControl = LoadControl(&quot;MyUserControl.ascx&quot;)
CType(c1, MyUserControl).BackColor = &quot;beige&quot;
Page.Controls.Add(c1)

I don't get what Ctype is trying to cast c1 as... it says type not defined.

Thanks.
 
It's trying to cast it as type:

MyUserControl


The class name doesn't necessarily HAVE to match the name of the file, though... so go to that file, and see what your class name is defined as, and make that type name match what you try to cast it as...

ie.
ctype(c1,myUserControl1).blahblah

And so forth...

Also, you don't need that Reference statement... Looks like you're trying to add the uc in code-behind. Just do it like this:

Dim c1 as myUserControl
c1 = LoadControl(&quot;myUserControl.ascx&quot;)
c1.property = value
placeHolder.Controls.Add(c1)

And so forth...

good luck! :)
paul
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
thanks that worked... but here's the tougher part.

My usercontrol has checkbox lists, dropdown boxes, etc, and I am going to by dynamically creating instances of hte user control depending on user input... any idea how i keep the id's of the individual controls withing hte user control to a format i want? and not the .net _ctl0_ tag prefix it uses? basically i don't want checkbox1 5 times, i want to control the name i used to access the properties.

thanks.
 
When you are creating the control set it's id to &quot;mycheckbox&quot; & x where x is a variable that increments each time you create a control. I don't think you can control what .net spits out as a name on the page though That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top