admin管理员组

文章数量:1336311

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

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

Share Improve this question edited Apr 22, 2009 at 13:19 Canavar 48.1k17 gold badges94 silver badges126 bronze badges asked Apr 22, 2009 at 12:19 Juan Carlos Blanco MartínezJuan Carlos Blanco Martínez 1,9776 gold badges25 silver badges29 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 1

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" />
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    LinkButton lb = e.Item.FindControl("btnDelete") as LinkButton;
    if (lb != mull) {
         lb.OnClientClick = "whatever";
     }
}

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.

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.

本文标签: cAdding javascript to a link39s OnClientClick property while binding a repeaterStack Overflow