(vb.net) Handling user-control events

Discussion in 'ASP .Net Building Controls' started by Yossi, Sep 12, 2003.

  1. Yossi

    Yossi Guest

    I created a web-project containg an .aspx file and a self-
    made User-Control (.acsx file) - all in vb.net.
    My aspx file contains a Submit button (which is not part
    of the User-Control).

    I dynamiclly create the User-Control (using
    the "LoadControl" command) and add it to a Panel located
    on my aspx file.

    I would like to save the values of the User-Control's
    form-fields - as a response to a click on the Submit
    button of my aspx file.

    What is the write way to do that (short code-sample would
    be great) ?
    Thanks in advance,
    Yossi
     
    Yossi, Sep 12, 2003
    #1
    1. Advertising

  2. "Yossi" <> wrote in message
    news:22e201c37903$39e5cc50$...
    > I created a web-project containg an .aspx file and a self-
    > made User-Control (.acsx file) - all in vb.net.
    > My aspx file contains a Submit button (which is not part
    > of the User-Control).
    >
    > I dynamiclly create the User-Control (using
    > the "LoadControl" command) and add it to a Panel located
    > on my aspx file.
    >
    > I would like to save the values of the User-Control's
    > form-fields - as a response to a click on the Submit
    > button of my aspx file.
    >
    > What is the write way to do that (short code-sample would
    > be great) ?
    > Thanks in advance,


    Expose the form fields as public properties of the user control:

    public string FormField1
    {
    get {return txtFormField1.Text;}
    }

    public int FormField2
    {
    get {return int.Parse(txtFormField2.Text);}
    }

    You can then refer to them in you button's Click event handler:

    private void Button_Click(object sender, EventArgs e)
    {
    // You can now refer to userControl.FormField1 and
    userControl.FormField2
    }
    --
    John Saunders
    Internet Engineer
     
    John Saunders, Sep 12, 2003
    #2
    1. Advertising

  3. Yossi

    Yossi Guest

    As far as I understand, you suggest handling form-fields
    of the User-Control within the aspx class. It means (in
    terms of design), that I expose the User-Control behaviour
    to the parent aspx class. I would like, on the other end,
    to handle the values of the User-Control's form-fields
    values within the control. Is it possible ?

    I would like to get the submit-button event in my aspx
    class, but instead of handling the event (saving the User-
    Control's form-fields values), pass the event to the User-
    Control. The User-Control will then handle the event by
    itself. This way, the User-Control is self-contained. It
    encpsulate the way to draw the control and also to save
    its data. How can I do that ?

    Thanks for the help so far,
    Yossi

    >-----Original Message-----
    >"Yossi" <> wrote in message
    >news:22e201c37903$39e5cc50$...
    >> I created a web-project containg an .aspx file and a

    self-
    >> made User-Control (.acsx file) - all in vb.net.
    >> My aspx file contains a Submit button (which is not part
    >> of the User-Control).
    >>
    >> I dynamiclly create the User-Control (using
    >> the "LoadControl" command) and add it to a Panel located
    >> on my aspx file.
    >>
    >> I would like to save the values of the User-Control's
    >> form-fields - as a response to a click on the Submit
    >> button of my aspx file.
    >>
    >> What is the write way to do that (short code-sample

    would
    >> be great) ?
    >> Thanks in advance,

    >
    >Expose the form fields as public properties of the user

    control:
    >
    >public string FormField1
    >{
    > get {return txtFormField1.Text;}
    >}
    >
    >public int FormField2
    >{
    > get {return int.Parse(txtFormField2.Text);}
    >}
    >
    >You can then refer to them in you button's Click event

    handler:
    >
    >private void Button_Click(object sender, EventArgs e)
    >{
    > // You can now refer to userControl.FormField1 and
    >userControl.FormField2
    >}
    >--
    >John Saunders
    >Internet Engineer
    >
    >
    >
    >.
    >
     
    Yossi, Sep 12, 2003
    #3
  4. Yossi

    Yossi Guest

    That is what I was tring to do,

    The problem is that after the submit operation, the form-
    fields get prefixes (i.e. cl1:myUserControlFormField) and
    sometimes their data is lost (in case of file-upload input
    fields). That is what I saw any way (I think it happens
    because I dynamically create the User-Control). Or, I may
    have done something wrong. I do the follwing:
    Upon Submit event (from the aspx file), I dynamically
    recreate the User-Control and calls the public event of
    the control in a similiar way to the one you explained.
    Then, the behaviour mentioned above occurs.

    Is there something diffrent I should do ?
    Thanks,
    Yossi

    P.S. It is the middle of the night (now in Israel :)) so
    I'm going to sleep and will read more answers (if any) in
    the morning. Thanks again, Yossi

    >-----Original Message-----
    >"Yossi" <> wrote in message
    >news:036301c3795b$888e5540$...
    >> As far as I understand, you suggest handling form-fields
    >> of the User-Control within the aspx class. It means (in
    >> terms of design), that I expose the User-Control

    behaviour
    >> to the parent aspx class. I would like, on the other

    end,
    >> to handle the values of the User-Control's form-fields
    >> values within the control. Is it possible ?
    >>
    >> I would like to get the submit-button event in my aspx
    >> class, but instead of handling the event (saving the

    User-
    >> Control's form-fields values), pass the event to the

    User-
    >> Control. The User-Control will then handle the event by
    >> itself. This way, the User-Control is self-contained. It
    >> encpsulate the way to draw the control and also to save
    >> its data. How can I do that ?

    >
    >You can create a public method in the user control which

    the page will call
    >on the button click. That way, the page knows that the

    user control can
    >perform this method, doesn't need to know anything about

    its internals.
    >Similarly, the user control won't care why this method

    got called - it will
    >save its fields regardless of which event called it.
    >--
    >John Saunders
    >Internet Engineer
    >
    >
    >
    >.
    >
     
    Yossi, Sep 13, 2003
    #4
    1. Advertising

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. Michael Craig
    Replies:
    0
    Views:
    454
    Michael Craig
    Jul 18, 2003
  2. ree32
    Replies:
    0
    Views:
    133
    ree32
    Sep 21, 2004
  3. Aaron
    Replies:
    3
    Views:
    237
    cfarahiii
    Jan 27, 2005
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    425
    Chris
    Aug 30, 2005
  5. Replies:
    1
    Views:
    167
    Peter Michaux
    Apr 27, 2007
Loading...

Share This Page