Events in 2 User Controls.

Posted on 2004-11-16
Last Modified: 2008-02-26
Here's my situation:

 I have a page ( Index.aspx), here i have 2 place holders and i have two different user controls. call them: uc1 and uc2 ( user control)

 Both these user controls have textboxes, and a submit button.

 Here is what i want to do:

 if uc1 button is clicked, i want to check if uc2 textboxes are filled first and call the submit button of the uc2 control -
 and then do a uc1 button click. I am trying to check if the user has login information in the uc2 control and then do a some button click on the uc1 control.

 the same way - if the user has some text information in the textboxes of uc1 and they click on the uc2 submit button - i want
to first finish uc2 button click and only then do a uc1 button submit.

By the way: there are some bussiness logic in each of these button submits.

 I am trying to combine the two on a page level and process both if some information is entered in either of the controls.

I know this has to be done using some bubbling of events, but dont know how to proceed.

Should i create a separate class to handle this, or just do it on the page..

Gurus, Any help is appreciated.

Thanks in advance.
Question by:steve_mick972
    LVL 28

    Expert Comment

    Hi steve_mick972,

    i suggest you to create the handler of both button to call same subroutine and pass as parameter to it the button
    then in this subroutine you will know which button was hit and do what you want

    for validating, you can out requiredfieldvalidators and just use Page.Validate

    LVL 22

    Accepted Solution

    No event bubbling. Just events, eventhandlers

    Assuming your usercontrol looks similar to

    Public Class MyControl1
     Inherits System.Web.UI.Control
     Implements INamingContainer

     Public Event SubmitClick As EventHandler
     Protected WithEvents MyButton1 as Button

     Protected Overridable Sub OnSubmitClick(e As EventArgs)
          RaiseEvent SubmitClick(Me, e)
     End Sub
     Private Sub MyButton1_OnClick(sender as Object, e as EventArgs) Handles MyButton1.Click
     End Sub

     Protected Overrides Sub OnInit()
     End Sub

     ... your code to initliaize the control...

    End Class

    Assuming you have two of these instances  declare don your page you can use the OnSubmitClick event of the control to do what you want. In your case you want to validate the controls of the other control. For this you can add a public function to the control which sends you sufficient information to make this check. Also add a function to actually submit the form.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    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…
    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…
    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…
    This video discusses moving either the default database or any database to a new volume.

    728 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

    20 Experts available now in Live!

    Get 1:1 Help Now