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




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com