Use delegate from WebUserControl to WebForm

I have ASP.NET (VB.NET) webApp.

My main form (called WebForm1) contains WebUserControl (called WebUserControl1).
WebUserControl1 contsins Button (called Button1).
On Button1 click-event, I want to trigger methos m() in WebForm1

I know the way to do it is Delegate but I cannot make it work appropriate

Thanx, El.

eladkaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ryerrasCommented:
yeah you can do that. First of all you need to declare the button in the user control as Public. By default when you add controls to Webform or user control. they are added as Protected. So, first step is to declare the button in the user control as public.

Then add an instance of user control to the webform. Then in the code behind of your Webform, declare the user control, as
Protected WebUserControl WebUserControl1;

Remember WebUserControl1should be the same as the id of the usercontrol you just added. Check for the id in the design mode of webform and varify both are same. Then in the Page_Load or wherever in your webform, add this

WebUserControl1.Button1.Click += new System.EventHandler(m);

by the way, method m() should have the signature of
 void m(object sender, System.EventArgs e)

Then only you can add it to the delegate.

HTH
0
s_sansanwalCommented:
0
eladkaAuthor Commented:
Thanx guys,

But I need this code in VB.NET (I don't know how to translate it - and make it work)

El.
0
ryerrasCommented:
AddHandler WebUserControl1.Button1.Click, AddressOf Me.m
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.