Using FindControls and Type casting

G

Guest

Hi Everyone,
I'm working on a sollution to one of my problems and have come across this
sample
Dim mySearch as POSearch = ctyap(Page.FindControl(POSearch1),
me.POSearch)
mySearch.Search(str)
"they sugested getting a reference to the user control before setting
properties like visible, one I'm having a issue with"

I have a couple user controls on this masterpage and I'd like to access them
but the system complains that (in the code above):
Type POSearch is not defined

I don't have a namespace defined for the masterpage or usercontrol (because
that cased other problems). In case you needed to know that.

How do I expose the Usercontrol as a type so that this could work?

Thanks
Michael
 
S

Swanand Mokashi

Why are you using Me.POSearch? -- may not be the root of the problem but
looks a little weird.
Try this :

Dim mySearch as POSearch

If Not Page.FindControl("POSearch1") Is Nothing Then
mySearch = Ctype(Page.FindControl("POSearch1"), POSearch)
Else
'Control Not found o nthe page
End If

That way you will know where the error is exactly happening


--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
 
G

Guest

You are right, I copied it over wrong. In my project I do have it like :
Dim mySearch as POSearch = ctype(Page.FindControl(POSearch1),POSearch)
mySearch.ShowResults()
and the system still can't find POSearch. I will change it to reflect your
code for safety. Thats if I can get this to work correctly. lol.
Thanks for the reply. I'm begenning to wonder if something else is going on,
because if I try to set the visible property of controls or Even ADD Items to
a dropdownlist in the usercontrol, it won't display the new items although
its list.count is correct.
Any items on the POSearch problem.
Thanks again, Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top