bairdmw Posted October 28, 2009 Posted October 28, 2009 I am creating dynamic ImageButtons (ie. a print icon for each row of a dynamic table). I can format the buttons and get them to PostBack, but I cannot work out how to handle the button click event. imgPrint = New ImageButton With imgPrint .CausesValidation = True .CommandName = "imgButton" .CommandArgument = drRuns("SchoolRunID") .ToolTip = "Print" .ImageUrl = "~/images/print.gif" End With I can't create an imgButton_onClick sub in the code behind file as imgButton is created dynamically at runtime, so it doesn't recognise this control/event in the code behind. I have got the following code in the Page_Load sub; If Not IsPostBack Then ' do some other stuff here Else ' this is where I want to know if an instance of imgButton was clicked ' how do I do it?? End If Can someone fill in the blanks for me please? THanks! Quote
bairdmw Posted October 28, 2009 Author Posted October 28, 2009 I have added the AddHandler statement and played around with a few other things, but still can't get this to work. With imgPrint .CommandName = "imgPrint_" & drRuns("SchoolRunID") .CommandArgument = drRuns("SchoolRunID") .AlternateText = "Print" : .ToolTip = "Print" .ImageUrl = "~/images/print.gif" AddHandler .Click, AddressOf imgPrint_Click End With Private Sub imgPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Response.Write("here") Response.End() End Sub The image buttons all format and display correctly, but when I click one I get a PostBack but the imgPrint.Click event does not fire the imgPrint_Click sub. Quote
Administrators PlausiblyDamp Posted October 28, 2009 Administrators Posted October 28, 2009 Which event are you adding the buttons in? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bairdmw Posted October 29, 2009 Author Posted October 29, 2009 Which event are you adding the buttons in? The buttons are being added as the page loads. I have a table which I am adding rows to at runtime. Each row has an ImageButton. The page is loading correctly and the buttons cause the page to PostBack, but I'm not sure how to catch the event when the PostBack occurs. Quote
bairdmw Posted November 9, 2009 Author Posted November 9, 2009 Can anyone help with this? Still can't work it out! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.