ImageButton在Repeater中的新页面中打开链接

时间:2014-11-21 15:35:19

标签: c# asp.net webforms

我有以下图像按钮,它位于转发器中:

<asp:ImageButton PostBackUrl='<%# DataBinder.Eval(Container.DataItem, "VesselId", "getattachment.do?VesselId={0}") %>' CausesValidation="false" ID="insurancestatus" runat="server"/>

因此,每次用户点击按钮时,都会显示他们的附件。

此要求已更改,附件必须在新页面上打开,因此我将以下内容添加到Repeater ItemDataBound事件中:

ImageButton imagebuttonInsurance = (ImageButton)e.Item.FindControl("insuranceStatus");
            imagebuttonInsurance.OnClientClick = String.Format("aspnetForm.target = '_blank'; return true()");

现在,当我点击图片时,它会打开另一个页面,但它只是重新加载新页面上的上一页。我尝试删除PostBackUrl并连接以下点击事件:

protected void insurancestatus_Click(object sender, ImageClickEventArgs e)
{
    Vessel vessel = (Vessel)e.Item.DataItem;
    Response.Redirect(String.Format("~/Secure/getattachment.do?VesselId={0}", vessel.VesselId));
}

但我无法处理该项目因此无法使用VesselId作为链接,我在哪里错了?

1 个答案:

答案 0 :(得分:1)

使用第二种方法,但使用命令参数属性,如:

 <asp:imagebutton runat=server...... commandargument='<%# Eval("vesselid") %>' />

然后:

protected void insurancestatus_Click(object sender, ImageClickEventArgs e)
{
    string vesselId = ((ImageButton)sender).CommandArgument;
   Response.Redirect(String.Format("~/Secure/getattachment.do?VesselId={0}", vesselId)); 
}
相关问题