referencing a User control through vb code

E

EO

Summary:
I have a user control containing 1 dropdownlist that's using
selectedindexchanged to raise a custom event. In the hosting page, I can't
get the raised event to fire (though the base event does fire within the
user control). The chief suspect is that in the hosting page, I haven't
found any code tricks that let me reference the user control or the
dropdownlist within the usercontrol through intellisense. This leads me to
believe that I'm blowing something in the declarations or whatever it takes
to properly reference my user control.

I'm using VB with codebehinds. Any insight on how to properly reference the
usercontrol would be appreciated. The hosting page contains:

<%@ Register TagPrefix="dropMyDept" TagName="MyDepts"
src="Controls/MyDepartmentList.ascx" %>

<dropMyDept:MyDepts id="DeptContext" OnChange="ChangeContext"
runat="server"></dropMyDept:MyDepts>


If you want the code I'm using for firing the custom event, ask and ye shall
receive.

-EO
 
G

Guest

In the code-behind, you need: protected withevents myControlID as myClass, where myControlID matches ID= on the instance of the user control, and myClass is the control class (MyDepartmentList). Declaring the instance gives you access to it, but you need the "withevents" if you want to catch any events coming out of there. Now you'll see the user control instance in your intellisense, but by design you won't see anything inside of it--you need to expose whatever you want the consumer to see, e.g. your own SelectedItemValue property of the user control might simply get/set SelectedItemValue of the dropdownlist (no reason to store private variables, etc.). You also need to make sure in the user control that you are declaring the events you want to raise as "public" so somebody else can see them. hth

----- EO wrote: ----

Summary
I have a user control containing 1 dropdownlist that's usin
selectedindexchanged to raise a custom event. In the hosting page, I can'
get the raised event to fire (though the base event does fire within th
user control). The chief suspect is that in the hosting page, I haven'
found any code tricks that let me reference the user control or th
dropdownlist within the usercontrol through intellisense. This leads me t
believe that I'm blowing something in the declarations or whatever it take
to properly reference my user control

I'm using VB with codebehinds. Any insight on how to properly reference th
usercontrol would be appreciated. The hosting page contains

<%@ Register TagPrefix="dropMyDept" TagName="MyDepts
src="Controls/MyDepartmentList.ascx" %><dropMyDept:MyDepts id="DeptContext" OnChange="ChangeContext
runat="server"></dropMyDept:MyDepts


If you want the code I'm using for firing the custom event, ask and ye shal
receive

-E
 
E

EO

Thank you.

I discovered that an example I had been trying to clone from an internet web
page had a typo in it! I'm trying to backtrack and find that page now so I
can send a polite email to the author. Somebody had copied *part* of their
code from the msdn library, leaving a confusing object reference
incompatibility.
 

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

Top