Is it possible to send a parameter in an ASP.Net image button OnClick event handler to a code-behind file?
In a DetailsView we have this markup for each day of the week for the Edit template and on top of that another bunch of coding for the insert template:
<EditItemTemplate>
<asp:ImageButton
ID="ImageButtonEditDayOfWeekMonday"
runat="server"
ImageUrl='<%# getCheckboxImageToDisplay(Eval("DayOfWeekMonday"))%>'
Height="15"
Width="15"
OnClick="ImageButtonEditDayOfWeekMonday_Click"
CausesValidation="False">
</asp:ImageButton>
</EditItemTemplate>
The handler in the code-behind file:
Protected Sub ImageButtonEditDayOfWeekTuesday_Click(sender As Object, e As ImageClickEventArgs)
Dim imgTheImageButton As New ImageButton
imgTheImageButton = DetailsView.FindControl("ImageButtonEditDayOfWeekTuesday")
If imgTheImageButton.ImageUrl = "../../Images/checked.png" = True Then
imgTheImageButton.ImageUrl = "../../Images/unchecked.png"
LabelCheckBoxTuesday.Text = False
Else
imgTheImageButton.ImageUrl = "../../Images/checked.png"
LabelCheckBoxTuesday.Text = True
End If
End Sub
That will amount to a lot of coding.
Is it possible to do create a single handler and call it like this?
OnClick="ImageButtonDayOfWeek_Click("Monday", "Edit")
The only difference between all the handlers is:
imgTheImageButton = DetailsView.FindControl("ImageButtonEditDayOfWeekTuesday")
It would be nice to just use a bunch of if statements inside a single handler and use the appropriate "ID" to place in DetailsView.FindControl.