Confirm Delete popup from a LinkButton in a repeater

S

Sandy

I have a repeater which shows Group names.

(Skip this part if you want rather irrelevant)
The groups are ordered and formatted:
Parent
---Child
------Grand Child

(okay start reading again please)

The code (html side) looks like this:



<table id="Table1">

<asp:Repeater id="rptGroups" runat="server"
OnItemCommand="Button_ItemCommand">

<HeaderTemplate>

</HeaderTemplate>

<ItemTemplate>

<tr>

<td>

<img width='<%# Int32.parse(DataBinder.Eval(Container.DataItem,
"lvl") * 20) %>' height="1" />

<asp:Label Runat="server" CssClass="FormFieldLabel">

<%# DataBinder.Eval(Container.DataItem, "GroupName") %>

</asp:Label>

</td>

<td>

<asp:LinkButton CommandName="ID"
Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>'
CommandArgument='<%#DataBinder.Eval(Container.DataItem, "GrpID")%>'
runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />

</td>

</tr>

</ItemTemplate>

<FooterTemplate>

</FooterTemplate>

</asp:Repeater>

</table>




the link button line:


<asp:LinkButton CommandName="ID"
Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>'
CommandArgument='<%#DataBinder.Eval(Container.DataItem, "GrpID")%>'
runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />




Creates a link button, sets the text = the value of
"SelectUserButtonName" property of the parent page (this phrase is
dynamically changed depending on the language of the user).

It adds a CommandArgument which happens to be the key field value for
that group. Currently when a user clicks the button the code collects
the value from the CommandArguement to know which row to work with.



Sub Button_ItemCommand(ByVal Sender As Object, _

ByVal e As RepeaterCommandEventArgs)

If e.CommandName = "ID" Then

'PopUp(e.CommandArgument.ToString() + " " + hdnFor.Value)

RaiseEvent UserSelected(e.CommandArgument.ToString)

End If

End Sub



I want to dynamically add code to confirm a delete.

I have done this before with regular buttons and link buttons however,
as this one seems to be dynamically added I can't refer to it by ID
because I get an error saying it doesn't exist.

Here is how the HTML renders right now:



<a id="ShowGroupMembership1_rptGroups__ctl6_Linkbutton1"
class="FormLnkBtn" href="javascript:{if (typeof(Page_ClientValidate)
!= 'function' || Page_ClientValidate())
__doPostBack('ShowGroupMembership1$rptGroups$_ctl6$Linkbutton1','')}
">Delete</a>




as you can see the id is NOT LinkButton1 anymore, so of course I
cannot find it.

Just to make things a bit more difficult, this is a control and
depending on parameters set it can either delete the group OR simply
Raise and event to the parent sending the key field value of the
selected group.

I am currently trying to get the confirm delete to work.

Thanks for your time!

I did find this c# link, but I work in VB and have not been able to
'translate' it.

http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx
 
G

Guest

Hi Sandy,

You can try to wrap your linkbutton with a <span> element that contains a java script confirmation message. For example:

<span onclick="return confirm('do you really want to delete this item?')">
<asp:LinkButton CommandName="ID"
Text='<%#DataBinder.GetPropertyValue(me, "SelectUserButtonName")%>'
CommandArgument='<%#DataBinder.Eval(Container.DataItem, "GrpID")%>'
runat="server" ID="Linkbutton1" CssClass="FormLnkBtn" />
</span>

You can customize the confirmation message by using <%=%> or <%#%> fragments.

Regards,

Mauricio
Sieena Software
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top