具有相同OnClick事件的两个Imagebutton。

时间:2012-05-20 11:30:28

标签: c# asp.net imagebutton

我有两个ImageButtons:

<asp:ImageButton ID="img1" runat="server" Width="50px" Height="50px" OnClick="CheckIMG" ImageUrl="../Icons/123.png" />
<asp:ImageButton ID="img2" runat="server" Width="50px" Height="50px" OnClick="CheckIMG" ImageUrl="../Icons/456.png" />

方法是:

protected void CheckIMG(object sender, ImageClickEventArgs e)
{
    HiddenField imgNameHF = (HiddenField)DetailsView1.FindControl("sent_info_to_db_HF");
    imgNameHF.Value = "'<%# CheckValue(Eval('" + img.ImageUrl + "')%>'";
}

我如何才能上线:用户访问的img.ImageUrl的{​​{1}}?

例如:

  • 如果点击ImageButton,则该行将为:img1

  • 如果点击img1.ImageUrl,则该行将为:img2

2 个答案:

答案 0 :(得分:3)

你可以试试这个。

protected void CheckIMG(object sender, ImageClickEventArgs e)
{
    HiddenField imgNameHF = (HiddenField)DetailsView1.FindControl("sent_info_to_db_HF");
    ImageButton imgb=(ImageButton) sender;
    imgNameHF.Value = "'<%# CheckValue(Eval('" + imgb.ImageUrl + "')%>'";
}

答案 1 :(得分:1)

你也可以试试这个:

protected void CheckIMG(object sender, ImageClickEventArgs e)
{
    HiddenField imgNameHF = (HiddenField)DetailsView1.FindControl("sent_info_to_db_HF");
    ImageButton imgb = sender as ImageButton;
    imgNameHF.Value = "'<%# CheckValue(Eval('" + imgb.ImageUrl + "')%>'";
}