Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically created buttonfield doesnt fire

Status
Not open for further replies.

daveonion

Programmer
Aug 21, 2002
359
GB
Hi,

I am creating numerous dataviews dynamically and adding a buttonfield, however on click of the button the event handler rowcommand doesnt fire, can anyone help am i missing something.

The code is below

sqldatagrid.CommandText = SQLdr("sqlcommandtext") & " where id =" & Session("Id")
sqlreadergrid = sqldatagrid.ExecuteReader
Dg(counter1) = New GridView
Dg(counter1).ID = "dg" & counter1
Dg(counter1).DataSource = sqlreadergrid
ButtonColumn(counter1) = New ButtonField
ButtonColumn(counter1).CommandName = "ViewForm"
ButtonColumn(counter1).ButtonType = ButtonType.Button
ButtonColumn(counter1).HeaderText = "View Form"
ButtonColumn(counter1).Text = "Picture"
Dg(counter1).Columns.Add(ButtonColumn(counter1))
AddHandler Dg(counter1).RowCommand, AddressOf AllGridView_RowCommand
AddHandler Dg(counter1).RowCreated, AddressOf GridView1_RowCreated
Dg(counter1).DataBind()
Panelbody(counter1).Controls.Add(Dg(counter1))


Protected Sub AllGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Dim label2 As New Label
label2.Text = sender.ID
UpdatePanel1.ContentTemplateContainer.Controls.Add(label2)
End Sub

Thanks in advance
 
A few things that spring to mind are:

1. There is no AddHandler for the actual ButtonColumn, so it may not be raising an event that would eventually get bubbled up to the RowCommand

2. It could be that the dynamic controls aren't getting recreated properly so double check that you are creating them each time the page is generated.

3. It could be that the UpdatePanel is interfering with how you think the page is flowing. If you must use an UpdatePanel, try disabling it whilst you are testing.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Hi Mark,

I dont think you can add a handler to the buttoncolumn, the actual rowcommand handler is meant to handle any click events.

Yes the dynamic control are being created correctly as i also have another handler created for mouse over and that works fine.

Any other ideas

Thanks
 
Can you provide a cut down version of the page that demonstrates the problem that we can use to test with? I'm still not convinced that it isn't something to with the control creation and/or the event handling but a test page should help to locate where the problem is.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Hi Mark, I orginally wasn't including the add control statement in the page init event, they were added in the click event of a find customer control. I have since moved the code to the page init event, and the event appears to work. The problem i have now is the page init event runs before the session variable is stored on the click event of the button, what do you recommend to solve this issue.
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top