Button Event Inside Table

B

Bishop

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
 
J

Jeffrey Palermo [MCP]

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
 
B

Bishop

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.
 
J

Jeffrey Palermo [MCP]

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 said:
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:%[email protected]...
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
outside
 
B

Bishop

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 said:
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 said:
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:%[email protected]...
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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top