Use delegate from WebUserControl to WebForm

Posted on 2004-11-07
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
    LVL 6

    Expert Comment

    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.

    LVL 9

    Expert Comment


    Author Comment

    Thanx guys,

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

    LVL 6

    Accepted Solution

    AddHandler WebUserControl1.Button1.Click, AddressOf Me.m

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now