Button Event Inside Table

Discussion in 'ASP .Net' started by Bishop, Nov 26, 2004.

  1. Bishop

    Bishop Guest

    I can't get my button event to fire inside a table. the button outside of
    the table works. Both make a postback.

    Any help appreciated.

    My code below.


    (Add button to page)

    Dim myButton As New Button

    myButton.ID = ButtonID.ToString

    myButton.Text = "Save"

    Page.FindControl("FORM1").Controls.Add(myButton)

    AddHandler myButton.Click, AddressOf btnAdd_Click





    (Add button to table cell)

    Dim myButton As New System.Web.UI.WebControls.Button

    myButton.ID = myDate.ToShortTimeString

    myButton.Text = myDate.ToShortTimeString

    myCell1.Controls.Add(myButton)

    AddHandler myButton.Click, AddressOf btnAdd_Click



    (Event)

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs)

    Dim myButton As Button

    myButton = CType(sender, Button)

    Dim myTemp As String = myButton.ID

    End Sub
    Bishop, Nov 26, 2004
    #1
    1. Advertising

  2. Bishop,
    The thing that stands out to me is that you are setting the Button ID to
    a date? This is probably changing from postback to postback. Events are
    wired up based on the uniqueID of each control, so this must remain the same
    from postback to postback. Another thing I see wrong is that you are
    setting properties before you add the control to the page. You should add
    the control to the page (or table cell) before you set any properties.

    Best regards,
    Jeffrey Palermo

    "Bishop" <> wrote in message
    news:%23%...
    > I can't get my button event to fire inside a table. the button outside of
    > the table works. Both make a postback.
    >
    > Any help appreciated.
    >
    > My code below.
    >
    >
    > (Add button to page)
    >
    > Dim myButton As New Button
    >
    > myButton.ID = ButtonID.ToString
    >
    > myButton.Text = "Save"
    >
    > Page.FindControl("FORM1").Controls.Add(myButton)
    >
    > AddHandler myButton.Click, AddressOf btnAdd_Click
    >
    >
    >
    >
    >
    > (Add button to table cell)
    >
    > Dim myButton As New System.Web.UI.WebControls.Button
    >
    > myButton.ID = myDate.ToShortTimeString
    >
    > myButton.Text = myDate.ToShortTimeString
    >
    > myCell1.Controls.Add(myButton)
    >
    > AddHandler myButton.Click, AddressOf btnAdd_Click
    >
    >
    >
    > (Event)
    >
    > Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs)
    >
    > Dim myButton As Button
    >
    > myButton = CType(sender, Button)
    >
    > Dim myTemp As String = myButton.ID
    >
    > End Sub
    >
    >
    Jeffrey Palermo [MCP], Nov 26, 2004
    #2
    1. Advertising

  3. Bishop

    Bishop Guest

    Thanks for the advice.

    The dates are pulled from a DB and are always going to be the same.

    I tried moving the properties after adding the control but didn't make any
    difference.




    "Jeffrey Palermo [MCP]" <http://dotnetjunkies.com/weblog/jpalermo> wrote in
    message news:%...
    > Bishop,
    > The thing that stands out to me is that you are setting the Button ID

    to
    > a date? This is probably changing from postback to postback. Events are
    > wired up based on the uniqueID of each control, so this must remain the

    same
    > from postback to postback. Another thing I see wrong is that you are
    > setting properties before you add the control to the page. You should add
    > the control to the page (or table cell) before you set any properties.
    >
    > Best regards,
    > Jeffrey Palermo
    >
    > "Bishop" <> wrote in message
    > news:%23%...
    > > I can't get my button event to fire inside a table. the button outside

    of
    > > the table works. Both make a postback.
    > >
    > > Any help appreciated.
    > >
    > > My code below.
    > >
    > >
    > > (Add button to page)
    > >
    > > Dim myButton As New Button
    > >
    > > myButton.ID = ButtonID.ToString
    > >
    > > myButton.Text = "Save"
    > >
    > > Page.FindControl("FORM1").Controls.Add(myButton)
    > >
    > > AddHandler myButton.Click, AddressOf btnAdd_Click
    > >
    > >
    > >
    > >
    > >
    > > (Add button to table cell)
    > >
    > > Dim myButton As New System.Web.UI.WebControls.Button
    > >
    > > myButton.ID = myDate.ToShortTimeString
    > >
    > > myButton.Text = myDate.ToShortTimeString
    > >
    > > myCell1.Controls.Add(myButton)
    > >
    > > AddHandler myButton.Click, AddressOf btnAdd_Click
    > >
    > >
    > >
    > > (Event)
    > >
    > > Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs)
    > >
    > > Dim myButton As Button
    > >
    > > myButton = CType(sender, Button)
    > >
    > > Dim myTemp As String = myButton.ID
    > >
    > > End Sub
    > >
    > >

    >
    >
    Bishop, Nov 26, 2004
    #3
  4. Bishop,
    If you can post a complete code sample that exhibits this behavior, it
    may be more obvious. Get rid of all code that isn't relevant to the problem
    at hand.

    Best regards,
    Jeffrey Palermo

    "Bishop" <> wrote in message
    news:...
    > Thanks for the advice.
    >
    > The dates are pulled from a DB and are always going to be the same.
    >
    > I tried moving the properties after adding the control but didn't make any
    > difference.
    >
    >
    >
    >
    > "Jeffrey Palermo [MCP]" <http://dotnetjunkies.com/weblog/jpalermo> wrote

    in
    > message news:%...
    > > Bishop,
    > > The thing that stands out to me is that you are setting the Button

    ID
    > to
    > > a date? This is probably changing from postback to postback. Events

    are
    > > wired up based on the uniqueID of each control, so this must remain the

    > same
    > > from postback to postback. Another thing I see wrong is that you are
    > > setting properties before you add the control to the page. You should

    add
    > > the control to the page (or table cell) before you set any properties.
    > >
    > > Best regards,
    > > Jeffrey Palermo
    > >
    > > "Bishop" <> wrote in message
    > > news:%23%...
    > > > I can't get my button event to fire inside a table. the button

    outside
    > of
    > > > the table works. Both make a postback.
    > > >
    > > > Any help appreciated.
    > > >
    > > > My code below.
    > > >
    > > >
    > > > (Add button to page)
    > > >
    > > > Dim myButton As New Button
    > > >
    > > > myButton.ID = ButtonID.ToString
    > > >
    > > > myButton.Text = "Save"
    > > >
    > > > Page.FindControl("FORM1").Controls.Add(myButton)
    > > >
    > > > AddHandler myButton.Click, AddressOf btnAdd_Click
    > > >
    > > >
    > > >
    > > >
    > > >
    > > > (Add button to table cell)
    > > >
    > > > Dim myButton As New System.Web.UI.WebControls.Button
    > > >
    > > > myButton.ID = myDate.ToShortTimeString
    > > >
    > > > myButton.Text = myDate.ToShortTimeString
    > > >
    > > > myCell1.Controls.Add(myButton)
    > > >
    > > > AddHandler myButton.Click, AddressOf btnAdd_Click
    > > >
    > > >
    > > >
    > > > (Event)
    > > >
    > > > Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
    > > > System.EventArgs)
    > > >
    > > > Dim myButton As Button
    > > >
    > > > myButton = CType(sender, Button)
    > > >
    > > > Dim myTemp As String = myButton.ID
    > > >
    > > > End Sub
    > > >
    > > >

    > >
    > >

    >
    >
    Jeffrey Palermo [MCP], Nov 26, 2004
    #4
  5. Bishop

    Bishop Guest

    I figured out that if I use mydate.hour & myday.min instead of a formated
    time, it works. I'm guessing it either didn't like the spaces or the ":" in
    the ID. At least it works. thanks for the suggestions!

    "Jeffrey Palermo [MCP]" <http://dotnetjunkies.com/weblog/jpalermo> wrote in
    message news:%23sU%...
    > Bishop,
    > If you can post a complete code sample that exhibits this behavior, it
    > may be more obvious. Get rid of all code that isn't relevant to the

    problem
    > at hand.
    >
    > Best regards,
    > Jeffrey Palermo
    >
    > "Bishop" <> wrote in message
    > news:...
    > > Thanks for the advice.
    > >
    > > The dates are pulled from a DB and are always going to be the same.
    > >
    > > I tried moving the properties after adding the control but didn't make

    any
    > > difference.
    > >
    > >
    > >
    > >
    > > "Jeffrey Palermo [MCP]" <http://dotnetjunkies.com/weblog/jpalermo> wrote

    > in
    > > message news:%...
    > > > Bishop,
    > > > The thing that stands out to me is that you are setting the Button

    > ID
    > > to
    > > > a date? This is probably changing from postback to postback. Events

    > are
    > > > wired up based on the uniqueID of each control, so this must remain

    the
    > > same
    > > > from postback to postback. Another thing I see wrong is that you are
    > > > setting properties before you add the control to the page. You should

    > add
    > > > the control to the page (or table cell) before you set any properties.
    > > >
    > > > Best regards,
    > > > Jeffrey Palermo
    > > >
    > > > "Bishop" <> wrote in message
    > > > news:%23%...
    > > > > I can't get my button event to fire inside a table. the button

    > outside
    > > of
    > > > > the table works. Both make a postback.
    > > > >
    > > > > Any help appreciated.
    > > > >
    > > > > My code below.
    > > > >
    > > > >
    > > > > (Add button to page)
    > > > >
    > > > > Dim myButton As New Button
    > > > >
    > > > > myButton.ID = ButtonID.ToString
    > > > >
    > > > > myButton.Text = "Save"
    > > > >
    > > > > Page.FindControl("FORM1").Controls.Add(myButton)
    > > > >
    > > > > AddHandler myButton.Click, AddressOf btnAdd_Click
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > > (Add button to table cell)
    > > > >
    > > > > Dim myButton As New System.Web.UI.WebControls.Button
    > > > >
    > > > > myButton.ID = myDate.ToShortTimeString
    > > > >
    > > > > myButton.Text = myDate.ToShortTimeString
    > > > >
    > > > > myCell1.Controls.Add(myButton)
    > > > >
    > > > > AddHandler myButton.Click, AddressOf btnAdd_Click
    > > > >
    > > > >
    > > > >
    > > > > (Event)
    > > > >
    > > > > Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
    > > > > System.EventArgs)
    > > > >
    > > > > Dim myButton As Button
    > > > >
    > > > > myButton = CType(sender, Button)
    > > > >
    > > > > Dim myTemp As String = myButton.ID
    > > > >
    > > > > End Sub
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Bishop, Nov 26, 2004
    #5
    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. Purvi T
    Replies:
    0
    Views:
    829
    Purvi T
    Oct 19, 2004
  2. jorge
    Replies:
    2
    Views:
    1,262
    jorge
    May 26, 2004
  3. sonic
    Replies:
    1
    Views:
    532
    John Saunders
    Jan 7, 2005
  4. Replies:
    8
    Views:
    4,926
    Lau Lei Cheong
    Mar 11, 2005
  5. jorge
    Replies:
    1
    Views:
    410
    Teemu Keiski
    May 28, 2004
Loading...

Share This Page