Button_Click event in user control not firing on page

Discussion in 'ASP .Net Web Controls' started by Tim Thomas, Oct 30, 2003.

  1. Tim Thomas

    Tim Thomas Guest

    Hi,
    I am very new to .NET and am in the process of building my first web
    application.
    I will briefly describe what i am trying to achieve:

    I have a system where suppliers register their details, their locations, and
    then add themselves to categories. Each category requires additional info
    from the suppliers, this additional category info is stored in its own DB
    table. a suppliers may add themselves to as many categories as required.
    the registration process is as follows:

    1. enter personal details
    2. select locations
    3 select category
    4 enter details for category
    [upon successfully completing stage 4, option to go back to stage 3 and add
    another category]

    I have got to stage 3 ok,
    this page has a dropdownList (and a button) to select the category, on
    button_Click a user control dynamically loads into a placeholder on the
    page, all works fine. this is the simplified code:

    private void btnCategory_Click(object sender, System.EventArgs e)
    {
    Control myControl = LoadControl(DropDownList1.SelectedItem.Text.Replace
    + ".ascx");
    PlaceHolder1.Controls.Add(myControl);
    }

    the control this loads is a simple webform page that has a form the supplier
    fills out and a button to 'send' the form (the button is within the .ascx
    user control). the button event should then add all the form data to a
    sqlCommand to add the text in each box to the stored procedure parameters.
    All this needs to happen withing the user control because it's quite
    different for each category. i hope your following me!
    when the control button is clicked all that happens is the page (that hosts
    the user control) reloads, the control dissapears, and the stored procedure
    (part of the button_click method within the user control) doesn't execute,
    and all i'm left with is the dropdown list again.

    What i need to happen is for the button_Click event to fire, do it's stuff
    and inform the user they were added, and ask them if they would like to add
    themselves to another category.

    I'm sure i am missing something fundamental and simple, but as i said i'm
    quite new to all this.

    Any help is greatly appreciated.

    Thanks
    Tim..
    Tim Thomas, Oct 30, 2003
    #1
    1. Advertising

  2. Tim Thomas

    HD Guest

    Hello Tim,

    Just put a break point on the buttons click event in the code behind file.
    and step into it.
    look at the various condition in the watch windows maybe some conditions you
    thought didnt work that way.

    regards,

    HD

    "Tim Thomas" <> wrote in message
    news:bnq5v5$2anj$...
    > Hi,
    > I am very new to .NET and am in the process of building my first web
    > application.
    > I will briefly describe what i am trying to achieve:
    >
    > I have a system where suppliers register their details, their locations,

    and
    > then add themselves to categories. Each category requires additional info
    > from the suppliers, this additional category info is stored in its own DB
    > table. a suppliers may add themselves to as many categories as required.
    > the registration process is as follows:
    >
    > 1. enter personal details
    > 2. select locations
    > 3 select category
    > 4 enter details for category
    > [upon successfully completing stage 4, option to go back to stage 3 and

    add
    > another category]
    >
    > I have got to stage 3 ok,
    > this page has a dropdownList (and a button) to select the category, on
    > button_Click a user control dynamically loads into a placeholder on the
    > page, all works fine. this is the simplified code:
    >
    > private void btnCategory_Click(object sender, System.EventArgs e)
    > {
    > Control myControl =

    LoadControl(DropDownList1.SelectedItem.Text.Replace
    > + ".ascx");
    > PlaceHolder1.Controls.Add(myControl);
    > }
    >
    > the control this loads is a simple webform page that has a form the

    supplier
    > fills out and a button to 'send' the form (the button is within the .ascx
    > user control). the button event should then add all the form data to a
    > sqlCommand to add the text in each box to the stored procedure parameters.
    > All this needs to happen withing the user control because it's quite
    > different for each category. i hope your following me!
    > when the control button is clicked all that happens is the page (that

    hosts
    > the user control) reloads, the control dissapears, and the stored

    procedure
    > (part of the button_click method within the user control) doesn't execute,
    > and all i'm left with is the dropdown list again.
    >
    > What i need to happen is for the button_Click event to fire, do it's stuff
    > and inform the user they were added, and ask them if they would like to

    add
    > themselves to another category.
    >
    > I'm sure i am missing something fundamental and simple, but as i said i'm
    > quite new to all this.
    >
    > Any help is greatly appreciated.
    >
    > Thanks
    > Tim..
    >
    >
    HD, Oct 30, 2003
    #2
    1. Advertising

  3. Tim Thomas

    Tim T Guest

    Thanks HD,
    I tried what you said, and it seems the code didn't even hit the breakpoint,
    so i couldn't see why the button click event in the user controls code
    behind wasn't firing
    It seems to me that clicking the button (which is part of the user control)
    on the page embedding the user control just reloads/does a post back for the
    page [hosting the control]- it doesn't fire any of the events in the user
    control :mad:
    Any other suggestions appreciated

    Tim..

    "HD" <> wrote in message
    news:...
    > Hello Tim,
    >
    > Just put a break point on the buttons click event in the code behind file.
    > and step into it.
    > look at the various condition in the watch windows maybe some conditions

    you
    > thought didnt work that way.
    >
    > regards,
    >
    > HD
    >
    > "Tim Thomas" <> wrote in message
    > news:bnq5v5$2anj$...
    > > Hi,
    > > I am very new to .NET and am in the process of building my first web
    > > application.
    > > I will briefly describe what i am trying to achieve:
    > >
    > > I have a system where suppliers register their details, their locations,

    > and
    > > then add themselves to categories. Each category requires additional

    info
    > > from the suppliers, this additional category info is stored in its own

    DB
    > > table. a suppliers may add themselves to as many categories as required.
    > > the registration process is as follows:
    > >
    > > 1. enter personal details
    > > 2. select locations
    > > 3 select category
    > > 4 enter details for category
    > > [upon successfully completing stage 4, option to go back to stage 3 and

    > add
    > > another category]
    > >
    > > I have got to stage 3 ok,
    > > this page has a dropdownList (and a button) to select the category, on
    > > button_Click a user control dynamically loads into a placeholder on the
    > > page, all works fine. this is the simplified code:
    > >
    > > private void btnCategory_Click(object sender, System.EventArgs e)
    > > {
    > > Control myControl =

    > LoadControl(DropDownList1.SelectedItem.Text.Replace
    > > + ".ascx");
    > > PlaceHolder1.Controls.Add(myControl);
    > > }
    > >
    > > the control this loads is a simple webform page that has a form the

    > supplier
    > > fills out and a button to 'send' the form (the button is within the

    ..ascx
    > > user control). the button event should then add all the form data to a
    > > sqlCommand to add the text in each box to the stored procedure

    parameters.
    > > All this needs to happen withing the user control because it's quite
    > > different for each category. i hope your following me!
    > > when the control button is clicked all that happens is the page (that

    > hosts
    > > the user control) reloads, the control dissapears, and the stored

    > procedure
    > > (part of the button_click method within the user control) doesn't

    execute,
    > > and all i'm left with is the dropdown list again.
    > >
    > > What i need to happen is for the button_Click event to fire, do it's

    stuff
    > > and inform the user they were added, and ask them if they would like to

    > add
    > > themselves to another category.
    > >
    > > I'm sure i am missing something fundamental and simple, but as i said

    i'm
    > > quite new to all this.
    > >
    > > Any help is greatly appreciated.
    > >
    > > Thanks
    > > Tim..
    > >
    > >

    >
    >
    Tim T, Oct 30, 2003
    #3
  4. Tim Thomas

    HD Guest

    Quick one Tim,

    The button is on a user control so how are you capturing the event. Think
    you'll have to go a bit deeper.
    With custom controls you have to inherit from IPostBackDataHandler and
    implement its RaisePostDataChangedEvent.
    I am still trying to figure out how to return the control to the control's
    container (Fire a custom event for the page possibly)
    so that any other manipulation other than that one the control goes through
    as well post the controls data manipulation,

    Dont think it will help to that an extent,

    HD
    "Tim T" <> wrote in message
    news:bnrqbu$2bt5$...
    > Thanks HD,
    > I tried what you said, and it seems the code didn't even hit the

    breakpoint,
    > so i couldn't see why the button click event in the user controls code
    > behind wasn't firing
    > It seems to me that clicking the button (which is part of the user

    control)
    > on the page embedding the user control just reloads/does a post back for

    the
    > page [hosting the control]- it doesn't fire any of the events in the user
    > control :mad:
    > Any other suggestions appreciated
    >
    > Tim..
    >
    > "HD" <> wrote in message
    > news:...
    > > Hello Tim,
    > >
    > > Just put a break point on the buttons click event in the code behind

    file.
    > > and step into it.
    > > look at the various condition in the watch windows maybe some conditions

    > you
    > > thought didnt work that way.
    > >
    > > regards,
    > >
    > > HD
    > >
    > > "Tim Thomas" <> wrote in message
    > > news:bnq5v5$2anj$...
    > > > Hi,
    > > > I am very new to .NET and am in the process of building my first web
    > > > application.
    > > > I will briefly describe what i am trying to achieve:
    > > >
    > > > I have a system where suppliers register their details, their

    locations,
    > > and
    > > > then add themselves to categories. Each category requires additional

    > info
    > > > from the suppliers, this additional category info is stored in its own

    > DB
    > > > table. a suppliers may add themselves to as many categories as

    required.
    > > > the registration process is as follows:
    > > >
    > > > 1. enter personal details
    > > > 2. select locations
    > > > 3 select category
    > > > 4 enter details for category
    > > > [upon successfully completing stage 4, option to go back to stage 3

    and
    > > add
    > > > another category]
    > > >
    > > > I have got to stage 3 ok,
    > > > this page has a dropdownList (and a button) to select the category, on
    > > > button_Click a user control dynamically loads into a placeholder on

    the
    > > > page, all works fine. this is the simplified code:
    > > >
    > > > private void btnCategory_Click(object sender, System.EventArgs e)
    > > > {
    > > > Control myControl =

    > > LoadControl(DropDownList1.SelectedItem.Text.Replace
    > > > + ".ascx");
    > > > PlaceHolder1.Controls.Add(myControl);
    > > > }
    > > >
    > > > the control this loads is a simple webform page that has a form the

    > > supplier
    > > > fills out and a button to 'send' the form (the button is within the

    > .ascx
    > > > user control). the button event should then add all the form data to

    a
    > > > sqlCommand to add the text in each box to the stored procedure

    > parameters.
    > > > All this needs to happen withing the user control because it's quite
    > > > different for each category. i hope your following me!
    > > > when the control button is clicked all that happens is the page (that

    > > hosts
    > > > the user control) reloads, the control dissapears, and the stored

    > > procedure
    > > > (part of the button_click method within the user control) doesn't

    > execute,
    > > > and all i'm left with is the dropdown list again.
    > > >
    > > > What i need to happen is for the button_Click event to fire, do it's

    > stuff
    > > > and inform the user they were added, and ask them if they would like

    to
    > > add
    > > > themselves to another category.
    > > >
    > > > I'm sure i am missing something fundamental and simple, but as i said

    > i'm
    > > > quite new to all this.
    > > >
    > > > Any help is greatly appreciated.
    > > >
    > > > Thanks
    > > > Tim..
    > > >
    > > >

    > >
    > >

    >
    >
    HD, Oct 30, 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. Tim Thomas
    Replies:
    3
    Views:
    798
  2. Tim T
    Replies:
    7
    Views:
    508
    Adam Carden
    Nov 1, 2003
  3. vatech1993
    Replies:
    4
    Views:
    5,675
    =?Utf-8?B?U8Opcmdpbw==?=
    Dec 11, 2004
  4. Don
    Replies:
    3
    Views:
    5,433
    Karl Seguin
    Mar 11, 2005
  5. Winshent
    Replies:
    1
    Views:
    651
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 17, 2005
Loading...

Share This Page