Today you encounter a button in repeater, click button and jump to another page.
Html.
1 <Asp:repeaterID= "Repeater"runat= "Server"OnItemCommand= "Repeater_itemcommand">2 <ItemTemplate>3 <Table>4 <TR>5 <TD>Id:<%# Eval("ID") %></TD>6 <TD>7 <%--<Asp:imagebutton ID="bnt12"IMAGEURL="~/help.png"runat="Server"CommandName="Jump"/>--%>8 <Asp:buttonrunat= "Server"Text= "Jump"ID= "Bnt1"CommandName= "Jump" />9 </TD>Ten </TR> One </Table> A </ItemTemplate> - </Asp:repeater>
Cs.
1 protected voidRepeater_itemcommand (Objectsource, RepeaterCommandEventArgs e)2 {3 if(E.commandname = ="Jump")4 {5Response.Redirect ("http://www.baidu.com");6 }7}
When I click on the button, I find that it won't jump.
On the internet has been looking for a lot of information, and finally found that the probable cause is
1. When the button is clicked refresh the page repeater again, the ItemCommand refreshed,
2. Use the Dopostback type to jump the page, both LinkButton.
Workaround: Do not let repeater rebind data or use Dopostback when clicking on the button.
About controls bound in repeater do not trigger ItemCommand events