R
RN1
Consider the following code:
------------------------------
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'binding data from DB to the Repeater
End If
End Sub
Sub ItemCmd(ByVal obj As Object, ByVal ea As
RepeaterCommandEventArgs)
'some code
End Sub
Sub BindData(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
If (ea.Item.ItemType = ListItemType.AlternatingItem Or
ea.Item.ItemType = ListItemType.Item) Then
Dim lnkDel As LinkButton
lnkDel = CType(ea.Item.FindControl("lnkDelete"),
LinkButton)
lnkDel.Attributes.Add("OnClick", "if(!confirm('Delete 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.DataItem("Col1") %>'
runat="server"/>
</td>
<td>
<asp:LinkButton ID="lnkCol2" CommandName='<%#
Container.DataItem("Col2") %>' Text='<%# Container.DataItem("Col2")
%>' runat="server"/>
</td>
<td>
<asp:Label ID="lblCol3" Text='<%# Container.DataItem("Col3") %>'
runat="server"/>
</td>
<td>
<asp:LinkButton 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.IsPostBack) Then
'binding data from DB to the Repeater
End If
End Sub
Sub ItemCmd(ByVal obj As Object, ByVal ea As
RepeaterCommandEventArgs)
'some code
End Sub
Sub BindData(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
If (ea.Item.ItemType = ListItemType.AlternatingItem Or
ea.Item.ItemType = ListItemType.Item) Then
Dim lnkDel As LinkButton
lnkDel = CType(ea.Item.FindControl("lnkDelete"),
LinkButton)
lnkDel.Attributes.Add("OnClick", "if(!confirm('Delete 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.DataItem("Col1") %>'
runat="server"/>
</td>
<td>
<asp:LinkButton ID="lnkCol2" CommandName='<%#
Container.DataItem("Col2") %>' Text='<%# Container.DataItem("Col2")
%>' runat="server"/>
</td>
<td>
<asp:Label ID="lblCol3" Text='<%# Container.DataItem("Col3") %>'
runat="server"/>
</td>
<td>
<asp:LinkButton 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