我在asp中创建了几个动态的asp:Panel:Lisview ItemTemplate。在面板中有一个HTML表,它被链接包围,因此整个div / box是可点击的。问题是linkbutton的OnClick事件没有在服务器端触发。有什么想法吗?
以下是代码:
<asp:Panel runat="server" ClientIDMode="Static">
<asp:LinkButton runat="server" ID="Link" OnClick="Link_Click" CausesValidation="false">
<table runat="server" id="Table" >
<thead>
<tr><th colspan="3"><%#Eval("abc")%></th></tr>
</thead>
<tbody>
<tr>
<td >
<asp:ImageButton runat="server" ImageUrl="../Images/img_4.png"/>
</td>
<td runat="server" class="data" >
<%#Eval("abc")%>
</td>
<td>
04:15
</td>
</tr>
</tbody>
</table>
</asp:LinkButton>
</asp:Panel>
LinkClick代码
protected void Link_Click(object sender, EventArgs e)
{
LinkButton link = (LinkButton)sender;
String id = link.ID;
if (id.StartsWith("T"))
Response.Redirect("Time.aspx?Id=" + id);
else
{
Response.Redirect("Chart.aspx?Id=" + id);
}
}
答案 0 :(得分:0)
我明白了。 asp:linkbutton id在后端代码中被重置,导致链接断开。这就是为什么点击不起作用的原因。