.NETGURU
Help: Simple user control
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.

Post a new message to this list...

VB Programmer
I create a simple user control and exposed a property, "MyProperty".

I dragged it onto a new webform. I want to access the exposed property
("MyProperty") of the user control. But, I cannot access the user control.
The (ID) property of the user control is set to "ucFilter", but trying to
access "ucFilter.MyProperty" doesn't work. (It says that 'ucFilter' is not
declared.)

Any ideas? Thanks.

Reply to this message...
 
    
Hermit Dave
in code behind declare a corresponding instance
so if your control looks something like this in design view
<UCFilter:UCFilter1 runat=server></UCFilter>

then go into your code behind and add

protected UCFilter UCFilter1;

after you have added this you should be able to access the property using
UCFilter1.MyProperty

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"VB Programmer" <Dont*NoSpam-Please*@jEmail.com> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
VB Programmer
I tried that but I keep getting this error: System.NullReferenceException:
Object reference not set to an instance of an object.

Here's what I did:
In my design view it looks like this:
<%@ Register TagPrefix="uc1" TagName="ucFilter" Src="ucFilter.ascx" %>
:
<uc1:ucfilter id="UcFilter1" runat="server"></uc1:ucfilter>

In my code behind:
Protected MyFilter As ucFilter
:
Response.Write(MyFilter.RegionalMgr) ' ERROR OCCURS!

Any ideas?

Thanks!

"Hermit Dave" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Karl
Protected UcFilter1 as UcFilter

Response.Write(UcFilter1.RegionalMgr)

you need to decalre your variable as the ID you give your in design view

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"VB Programmer" <Dont*NoSpam-Please*@jEmail.com> wrote in message
news:Click here to reveal e-mail address...
> I tried that but I keep getting this error:
System.NullReferenceException:
[Original message clipped]

Reply to this message...
 
    
William F. Robertson, Jr.
As Hermit was saying, your ID property "UcFilter1" should be the same as the
object name.

Instead of:
Protected MyFilter As ucFilter
Try
Protected UcFilter1 As ucFilter

Then use the name UcFilter throughout your codebehind.

HTH,

bill

"VB Programmer" <Dont*NoSpam-Please*@jEmail.com> wrote in message
news:Click here to reveal e-mail address...
> I tried that but I keep getting this error:
System.NullReferenceException:
[Original message clipped]

Reply to this message...
 
    
VB Programmer
That was it! Thanks everyone!!!!!

"William F. Robertson, Jr." <wfrobertson_at_kpmg_dot_com> wrote in message
news:%Click here to reveal e-mail address...
> As Hermit was saying, your ID property "UcFilter1" should be the same as
the
[Original message clipped]

Reply to this message...
 
 
System.NullReferenceException




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification