ASP.NetイメージボタンのOnClickイベントハンドラーのパラメーターを分離コードファイルに送信することは可能ですか?
DetailsViewには、編集テンプレートの曜日ごとにこのマークアップがあり、その上に挿入テンプレートの別のコーディングがあります。
<EditItemTemplate>
<asp:ImageButton
ID="ImageButtonEditDayOfWeekMonday"
runat="server"
ImageUrl='<%# getCheckboxImageToDisplay(Eval("DayOfWeekMonday"))%>'
Height="15"
Width="15"
OnClick="ImageButtonEditDayOfWeekMonday_Click"
CausesValidation="False">
</asp:ImageButton>
</EditItemTemplate>
コードビハインドファイルのハンドラー:
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
それは多くのコーディングになります。
単一のハンドラーを作成して、このように呼び出すことは可能ですか?
OnClick="ImageButtonDayOfWeek_Click("Monday", "Edit")
すべてのハンドラーの唯一の違いは次のとおりです。
imgTheImageButton = DetailsView.FindControl("ImageButtonEditDayOfWeekTuesday")
単一のハンドラー内で一連のifステートメントを使用し、適切な「ID」を使用してDetailsView.FindControlに配置すると便利です。