Calling methods inside a user control from the container control

Discussion in 'ASP .Net' started by =?Utf-8?B?TmVpbA==?=, Aug 25, 2004.

  1. Hi,

    I have an aspx page page with some existing controls code etc. This page has
    an update button which updates a SQL Db based on any user changes. I need to
    add a new section to this page and a few other pages. I think that it's best
    to create a user control for this purpose. This user control will contain a
    number of webcontrols e.g textbox, dropdown etc When the user clicks update
    on the main page I need to update the DB as before for the original controls
    plus the new ones from the user control.

    What is the best way to do this? I thought that the user control should have
    its own methods to take care of the updates but how should the main page call
    these methods or is there a better way to do this?
     
    =?Utf-8?B?TmVpbA==?=, Aug 25, 2004
    #1
    1. Advertisements

  2. Karl

    Karl Guest

    The best way, in my opinion, is to have the page raise an event, which the
    user controls are hooked into.

    Basically, your page defines an event:
    Public Event Save As EventHandler

    on the click event of the page, you raise the event:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    RaiseEvent Save(Me, e)
    End Sub

    in the user control(s) you hook into the event:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    AddHandler CType(Page, TYPEOFPAGEHERE).Save, AddressOf OnSave
    'TYPEOFPAGEHERE is going to be like WebForm1 or something
    End Sub

    and then you have your control's save function:

    Private Sub OnSave(ByVal source As Object, ByVal e As EventArgs)
    'do your magic here
    End Sub

    Karl

    "Neil" <> wrote in message
    news:...
    > Hi,
    >
    > I have an aspx page page with some existing controls code etc. This page

    has
    > an update button which updates a SQL Db based on any user changes. I need

    to
    > add a new section to this page and a few other pages. I think that it's

    best
    > to create a user control for this purpose. This user control will contain

    a
    > number of webcontrols e.g textbox, dropdown etc When the user clicks

    update
    > on the main page I need to update the DB as before for the original

    controls
    > plus the new ones from the user control.
    >
    > What is the best way to do this? I thought that the user control should

    have
    > its own methods to take care of the updates but how should the main page

    call
    > these methods or is there a better way to do this?
     
    Karl, Aug 25, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver Wong
    Replies:
    14
    Views:
    1,900
    Chris Uppal
    Jun 13, 2006
  2. wolverine
    Replies:
    2
    Views:
    571
    Marcus Kwok
    Jul 24, 2006
  3. none
    Replies:
    8
    Views:
    540
  4. Kiran More
    Replies:
    2
    Views:
    470
    Kiran More
    Nov 14, 2006
  5. Kenneth McDonald
    Replies:
    5
    Views:
    600
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page