Consider the following code:
------------------------------
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBac k) Then
'binding data from DB to the Repeater
End If
End Sub
Sub ItemCmd(ByVal obj As Object, ByVal ea As
RepeaterCommand EventArgs)
'some code
End Sub
Sub BindData(ByVal obj As Object, ByVal ea As
RepeaterItemEve ntArgs)
If (ea.Item.ItemTy pe = ListItemType.Al ternatingItem Or
ea.Item.ItemTyp e = ListItemType.It em) Then
Dim lnkDel As LinkButton
lnkDel = CType(ea.Item.F indControl("lnk Delete"),
LinkButton)
lnkDel.Attribut es.Add("OnClick ", "if(!confirm('D elete this
record?')) return false;")
End If
End Sub
</script>
<form runat="server">
<asp:Repeater ID="rptrCols" OnItemCommand=" ItemCmd"
OnItemDataBound ="BindData" runat="server">
<HeaderTemplate >
<table>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
<th>Delete</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:Label ID="lblCol1" Text='<%# Container.DataI tem("Col1") %>'
runat="server"/>
</td>
<td>
<asp:LinkButt on ID="lnkCol2" CommandName='<% #
Container.DataI tem("Col2") %>' Text='<%# Container.DataI tem("Col2")
%>' runat="server"/>
</td>
<td>
<asp:Label ID="lblCol3" Text='<%# Container.DataI tem("Col3") %>'
runat="server"/>
</td>
<td>
<asp:LinkButt on ID="lnkDelete" Text="DELETE" runat="server"/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:Repeater>
</form>
------------------------------
When the DELETE link is clicked, a JavaScript confirm dialog pops-up.
This is what the above code does. But if I move the entire (JavaScript
confirm dialog) code from the OnItemDataBound event function to the
OnItemCommand event function, the JavaScript confirm dialog doesn't
pop-up when the DeLETE link is clicked. Why?
Thanks,
Ron
------------------------------
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBac k) Then
'binding data from DB to the Repeater
End If
End Sub
Sub ItemCmd(ByVal obj As Object, ByVal ea As
RepeaterCommand EventArgs)
'some code
End Sub
Sub BindData(ByVal obj As Object, ByVal ea As
RepeaterItemEve ntArgs)
If (ea.Item.ItemTy pe = ListItemType.Al ternatingItem Or
ea.Item.ItemTyp e = ListItemType.It em) Then
Dim lnkDel As LinkButton
lnkDel = CType(ea.Item.F indControl("lnk Delete"),
LinkButton)
lnkDel.Attribut es.Add("OnClick ", "if(!confirm('D elete this
record?')) return false;")
End If
End Sub
</script>
<form runat="server">
<asp:Repeater ID="rptrCols" OnItemCommand=" ItemCmd"
OnItemDataBound ="BindData" runat="server">
<HeaderTemplate >
<table>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
<th>Delete</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td>
<asp:Label ID="lblCol1" Text='<%# Container.DataI tem("Col1") %>'
runat="server"/>
</td>
<td>
<asp:LinkButt on ID="lnkCol2" CommandName='<% #
Container.DataI tem("Col2") %>' Text='<%# Container.DataI tem("Col2")
%>' runat="server"/>
</td>
<td>
<asp:Label ID="lblCol3" Text='<%# Container.DataI tem("Col3") %>'
runat="server"/>
</td>
<td>
<asp:LinkButt on ID="lnkDelete" Text="DELETE" runat="server"/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:Repeater>
</form>
------------------------------
When the DELETE link is clicked, a JavaScript confirm dialog pops-up.
This is what the above code does. But if I move the entire (JavaScript
confirm dialog) code from the OnItemDataBound event function to the
OnItemCommand event function, the JavaScript confirm dialog doesn't
pop-up when the DeLETE link is clicked. Why?
Thanks,
Ron
Comment