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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Buttons not firing on Client Server but work in Dev?!

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
0
0
GB
Hi

I've got a datagrid that has dynamic buttons created in some of the cells. When the user clicks them, depending on the value in the cell, they'll either receive a confirmation form or an error message, both of which are forms in div tages so are just being shown & hidden accordingly. This all works fine on my dev pc in both IE6 & IE7. However....as soon as upload it to the client's server I get "Object reference not set to an instance of an object.
at XXX.uc1.btn_Click(Object sender, EventArgs e)" when the button is clicked. Also strangely when you hover over the button on the client site, there is no text in the status bar, but in dev, it shows the current page's link.

I'm developing on XP sp2 with IIS 5.1, .net 1.1.4322.573 and so is the client pc

in my datagrid itemdatabound I've got

btn = New Button

btn.Text = "Build"

btn.ID = e.Item.Cells(i).Text

btn.CssClass = "btnBuild"

AddHandler btn.Click, AddressOf btn_Click

e.Item.Cells(i).Controls.Add(btn)

Then

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Select Case CType(sender, Button).Text

Case "Cancel"

divError.Style.Item("display") = "block"

DivShim.Style.Item("display") = "block"

Case "Empty Slot"

divConfirm.Style.Item("display") = "block"

DivShim2.Style.Item("display") = "block"

End Select

Any pointers would be greatly appreciated as I can't work out why it won't work.

Cheers

Lbob
 
your creating the buttons dyanmically which means they must be created on every page load. you need to create them in the rowcreated event not the rowdatabound event.

another option:
instead of dynamically creating buttons, you should declaratively difine the buttons and set the visible property of the control in the rowdatabound event.

I also find it's easier to work with the RowCommand event rather than creating seperate event handlers for each button

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top