[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Use delegate from WebUserControl to WebForm

Posted on 2004-11-07
Medium Priority
Last Modified: 2012-06-27
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.

Question by:eladka
  • 2

Expert Comment

ID: 12518008
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.


Expert Comment

ID: 12518636

Author Comment

ID: 12522887
Thanx guys,

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


Accepted Solution

ryerras earned 500 total points
ID: 12523311
AddHandler WebUserControl1.Button1.Click, AddressOf Me.m

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question