Groups | Blog | Home
all groups > asp.net > november 2004 >

asp.net : Button Event Inside Table


Bishop
11/25/2004 9:58:17 PM
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]
11/25/2004 10:20:24 PM
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

[quoted text, click to view]

Bishop
11/25/2004 10:37:59 PM
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:%23pReD920EHA.804@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

Jeffrey Palermo [MCP]
11/25/2004 11:27:42 PM
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

[quoted text, click to view]

Bishop
11/26/2004 9:15:17 AM
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%23qi30EHA.2568@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button