Link to home
Start Free TrialLog in
Avatar of alivemedia
alivemedia

asked on

delete confirm popup on asp hyperlink inside repeater control?

I want to add a confirm delete javascript to my delete hyperlink's inside a repeater control, anyone have any ideas?

Here's my aspx code:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
        <div style="float:left; padding:10px; text-align:center;">
            <asp:HyperLink ID="ImageLink" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageId","~/propertyimages/{0}-sm.jpg") %>' NavigateUrl='#' /><br />
            <asp:HyperLink ID="DeleteLink" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ImageId","ViewProperty.aspx?PropertyId="+Request.QueryString("PropertyId")+"&ImageId={0}") %>'  >Delete</asp:HyperLink>
        </div>
        </ItemTemplate>
    </asp:Repeater>
ASKER CERTIFIED SOLUTION
Avatar of Jason Scolaro
Jason Scolaro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alivemedia
alivemedia

ASKER

Sweet, thanks.  I used the ItemDataBound technique and it works perfectly.
or you could do it this way...even simpler ;)


<span onclick="return confirm('Do you really want to delete this record?');"> <asp:HyperLink ID="DeleteLink" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ImageId","ViewProperty.aspx?PropertyId="+Request.QueryString("PropertyId")+"&ImageId={0}") %>'  >Delete</asp:HyperLink></span>
Sorry ..I didnt see Jason's post....My apologies
rajesh75,

That was my #1 proposal (of the 2 for .NET 1.1).... :-)

-- Jason
In the accepted solution, accepted for .net 2.0 is :
<asp:HyperLink OnClientClick="return confirm('Are you sure?');" ID="DeleteLink" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ImageId","ViewProperty.aspx?PropertyId="+Request.QueryString("PropertyId")+"&ImageId={0}") %>'  >Delete</asp:HyperLink>

But using NavigateUrl means it redirects to specified URL. To use Postback feature of dot net, its better to use :
<asp:LinkButton ID="LinkButton1" CommandName="Fold" OnClientClick="return confirm('Are you sure?');" CommandArgument='<%# Eval("Folder_Id") %>' runat="server">LinkButton</asp:LinkButton>
and in Rpt_ITemcommand event :
if (e.CommandName == "Fold")
        {
            string foldid = e.CommandArgument.ToString();
..
is better one.