By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Custom Control RaiseEvent

P: n/a
I cannot figure out what I'm doing wrong, can someone shed some light on
this for me?

I have the following code inside a working user control (MyControl):

Public Event SubmitClick(ByVal sender As Object, ByVal e As EventArgs)
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

RaiseEvent SubmitClick(sender, e)

End Sub

In the code-behind of the calling page I have this:

Protected WithEvents ctrlMyControl As MyControl
Private Sub ctrlMyControl_SubmitClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ctrlMyControl.SubmitClick

End Sub

When I run it through the debugger, the RaiseEvent line fires, but none of
the code in the code-behind runs.

Thanks in advance for any assistance you can lend!

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a

Make sure the instance of MyControl which is raising the event is in
the same place where you have placed the handler.

..NET Developer

probably the full code would make more clear what you are doing. In
case, try also declaring the event as SHARED to see
if it is a scope problem.

Nov 21 '05 #2

P: n/a
Thank you for the asssitance.
I have found some additional information.

I am currently using the custom control in the EditItemTemplate of a
datalist. When I pull the control out of the datalist, the events fire
What am I missing in order to wire up the events when using it in the

I tried adding this code to the EditCommand routine:

AddHandler MyControl.SubmitClick, AddressOf ctrlMyControl_SubmitClick

But received an "object not set to an instance" error.
Thanks again for any assistance!
Nov 21 '05 #3

P: n/a
Check if you have a duplicate construction
something like:

dim withevents Control as new control
control = new control

so that the instance which you are passing the delegate
is not the same which is used later on ...
..NET Developer

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.