views:

1905

answers:

4

Hi,

I'm trying to get this working but no success:

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="btnDeleteFamily_Click">
 <HeaderTemplate>
    <table>
       <tr>
          <th width="90" valign="top"><%=getTag("name")%></th>
       </tr>
 </HeaderTemplate>
 <ItemTemplate>
       <tr>
       <td><%#Eval("chrname")%></td>
           <asp:LinkButton ID="btnDeleteFamily" CssClass="fRight ui-icon ui-icon-trash" runat="server" CommandName="delete" CommandArgument='<%#Eval("idmember")%>' OnClientClick='return confirm("<%= getTag("deletefamilymemberdialog") %>")' Text="" ValidationGroup="delete_family" />
       </td>
       </tr>
  </ItemTemplate>
  <FooterTemplate>
     </table>
  </FooterTemplate>
</asp:Repeater>

When clicking on the btnDeleteFamily OnClientClick the confirm dialog is not shown.

getTag (method in the code behind) is used for localization to get the text depending on the language. My intention is to show that message in the JavaScript dialog, but I'm getting:

<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$rptFamily$ctl01$btnDeleteFamily','')" class="fRight ui-icon ui-icon-trash" id="ctl00_ContentPlaceHolder1_rptFamily_ctl01_btnDeleteFamily" onclick='return confirm("<%= getTag("deletefamilymemberdialog") %>");'/>

So it's not processing getTag in the server side otherwise I would be getting

onclick='return confirm("Are you sure that you want to delete this entry?");'

Thanks

A: 

It seems to be ok, for me at least.

You could try it in firefox, and using the WebDeveloper toolbar or Firebug extensions you will be able to get more information about what is happening behind scene.

Maybe there are others errors on the page that doesn't allow this code to work.

eKek0
Hi Ekeko,It is not ok, as in the browser I'm getting onclick='return confirm("<%= getTag("deletefamilymemberdialog") %>");' and I should be getting something like onclick='return confirm("Are you sure that you want to delete this entry?");'
Juan Carlos Blanco Martínez
A: 

I think writing the message to page as a javascript variable is a better solution :

<script>
   var deleteMemberDialogMessage = '<%= getTag("deletefamilymemberdialog") %>';
</script>

And your repeater :

<asp:LinkButton ID="btnDeleteFamily" CssClass="fRight ui-icon ui-icon-trash"
    runat="server" CommandName="delete" CommandArgument='<%#Eval("idmember")%>' 
    OnClientClick='return confirm(deleteMemberDialogMessage)' Text="" 
    ValidationGroup="delete_family" />

By the way be sure that your deletefamilymemberdialog message doesn't have single quote.

EDIT : If you want to bind a value from your datasource to your repeater, you should bind your column to control instead of Response.Write (<%=) like that :

<asp:LinkButton ID="btnDeleteFamily" CssClass="fRight ui-icon ui-icon-trash"
 runat="server" CommandName="delete" CommandArgument='<%#Eval("idmember")%>' 
OnClientClick='<%# Bind("return confirm('{0}');'", "YourColumnName") %> Text="" 
ValidationGroup="delete_family" />
Canavar
What if you had to pass a value from the repeater, using Eval()? How would you do that?
Juan Carlos Blanco Martínez
I suggest this to your solution, it looks like you're showing a static message.
Canavar
Yes, I agree, but what if the message would depend on some value in the Repeater. Just wondering...
Juan Carlos Blanco Martínez
Canavar, could you change <code>OnClientClick='return confirm(deleteMemberDialogMessage) %>")'</code> into <code>OnClientClick='return confirm(deleteMemberDialogMessage)'</code> and your answer will be the right one. Thanks
Juan Carlos Blanco Martínez
yes you're right, I also update my answer to your question.
Canavar
Sorry but I didn't explain myself clearly. I meant what if you want to do something like <code>OnClientClick='return confirm("<%# getTag(Eval("chrname")) %>")'</code>. Do you understand me?
Juan Carlos Blanco Martínez
+1  A: 
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    LinkButton lb = e.Item.FindControl("btnDelete") as LinkButton;
    if (lb != mull) {
         lb.OnClientClick = "whatever";
     }
}
Chad Grant
A: 

If you want to use the jQuery dialog in confirmation mode to bind to link buttons on a repeater inside an update panel, AND the code you want to execute after confirmation is different for each row, you can set it up this way:

Add a javascript function to your page/control like this:

function confirm(buttonFunctionForPostBack)
{
    $("#dialog").dialog('option', 'buttons', { 
              "Cancel": function() { 
                  $(this).dialog("close"); 
              },
              "Delete Payment": function () { 
                  eval(buttonFunctionForPostBack); 
                  $(this).dialog("close"); 
                  }
              }
    ).dialog('open');
}

And in your code behind:

public void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    LinkButton lb = e.Item.FindControl("deleteButton") as LinkButton;
    if (lb != null)
    {
        lb.OnClientClick = "confirm(\"" + this.Page.ClientScript.GetPostBackEventReference(lb, string.Empty) + "\");return false;";
    }
}

And in your aspx page:

<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
  <HeaderTemplate>
    <table>
       <tr>
          <th width="90" valign="top"></th>
       </tr>
 </HeaderTemplate>
 <ItemTemplate>
       <tr>
         <td><%#Eval("name")%></td>
         <td><asp:LinkButton ID="deleteButton" runat="server" CommandName="delete" CommandArgument='<%#Eval("id")%>' Text="Delete" />
         </td>
       </tr>
  </ItemTemplate>
  <FooterTemplate>
     </table>
  </FooterTemplate>
</asp:Repeater>

This lets you take advantage of the fact that you can set the dialog's 'buttons' option after the dialog was created. Also, it doesn't require any extra script variables.

ranomore