473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using FindControls and Type casting

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
Apr 26 '06 #1
2 1560
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
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
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

Apr 26 '06 #2
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

"Swanand Mokashi" wrote:
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
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
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


Apr 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: scrimp | last post by:
Ive been using PAMIE 1.4 to try to automate web page processes. The one thing I cannot do with it is upload files and download files. With uploading files, the file input box does not allow PAMIE...
7
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play...
23
by: René Nordby | last post by:
Hi there, Is there anyone that knows how to do the following? I have a class A and a class B, that 100% inherits from class A (this means that I don't have other code in class B, than...
8
by: Michael | last post by:
Hi, I think my problem deals with class casting and inheritance. I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes),...
1
by: Thiero | last post by:
Hi I posted s thread but did have any reply, I am a new programmer and really wants someone to help me on how to use TreeMap for this code cos I want to it to be able to handle the options from 6...
15
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
5
by: aaragon | last post by:
Hi everyone, I wrote a very simple function to try to understand the casting of variables in C++. The function is function foo() { std::vector<inttest(100); randomize(test); unsigned long...
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
14
by: KK | last post by:
Dear All I have a small problem with using as operator on value type array. Here is an example what I am trying to do. using System; using System.Collections.Generic; using System.Text;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.