I am using a repeater to make a table with customers and the first column is supposed to have two buttons, one for edit, one for delete. When I put these ImageButtons in there, they do not go to my designer. This then causes me to not be able to have a VB method that handles the click of them.
<asp:ImageButton ID="btnEdit" runat="server" CssClass ="btn" ImageUrl="..." Width="50%" Height ="50%"/>
<asp:ImageButton ID="btnDelete" runat="server" CssClass ="btn red-btn" ImageUrl="..." Width="50%" Height ="50%"/>
These are my buttons.
Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEdit.Click
Response.Redirect("UpdateCustomer.aspx")
End Sub
I tried to just manually input the buttons into the designer.vb but it doesn’t work still. It isn’t recognizing those buttons in the aspx form.
2
Answers
Okay, I found a solution. Instead of using Handles button.click I needed to add OnClick to the image button. I am no exactly sure why I have to do it this way though.
You can do this several ways.
One cute way is to drag + drop the button onto the form OUTSIIDE of the data repeating control (listview, gridview, repeater, etc.).
that way, you can display the property sheet – including the events tab, and add the event (or even double click on the control if it is a button, or say image button).
However, as a general rule, such controls when nested inside a control, then you can’t "click" on the control.
So, the most common way and in fact some developers don’t even use the property sheet?
You type in the event in markup, and let intel-sense kick in.
Say, I have a image button in by gv, say like this:
So, as you can see, intel-sense will "pop" a dialog create event for you, select that, and when you flip to code behind, then you find the event stub having been created for you.