Help: Simple user control

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

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.
 
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)
 
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!
 
Protected UcFilter1 as UcFilter

Response.Write(UcFilter1.RegionalMgr)

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

Karl
 
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
 
That was it! Thanks everyone!!!!!

William F. Robertson said:
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
 
Back
Top