简体   繁体   中英

call javascript function from imagebutton click asp.net 1.1

i have a javascript function:

      function confirmerSupprimer()
      {
        var confirm=confimrm("est vous sur de vouloir supprimer ce facturation");
        if(confimrm==false)
          return false;
      }
    </script>

inside a datagrid: i have

<asp:TemplateColumn>
                                <HeaderStyle Width="15%"></HeaderStyle>
                                <ItemTemplate>
                                    <asp:ImageButton id="ibEdit" runat="server" CommandName="update" ImageUrl="./Images/edit.gif" AlternateText="Editer"></asp:ImageButton>
                                    <asp:ImageButton id="ibDelete" runat="server" CommandName="delete" ImageUrl="./Images/del.gif"
                                                            AlternateText="Supprimer" OnClick="confirmerSupprimer();"></asp:ImageButton>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:ImageButton id="ImageButton6" runat="server" CommandName="update" ImageUrl="images/save.gif"
                                        AlternateText="Valider"></asp:ImageButton>

                                    <asp:ImageButton id="ImageButton4" runat="server" CommandName="cancel" ImageUrl="./Images/cancel.gif"
                                        AlternateText="Annuler"></asp:ImageButton>
                                </EditItemTemplate>

Error:

BC30456: 'confirmerSupprimer' not aa member of 'ASP.Facturation_aspx'.

What's the pb

This function is declared in JavaScript - your GridView is expecting a method declared in C# —that's why you're getting that error.

If you want to wire this image button up with that JavaScript function, you could add this call to the Attributes collection in your code behind.

<asp:DataGrid OnItemDataBound="yourDataGrid_RowDataBound" 

protected void yourDataGrid_RowDataBound(object sender, DataGridItemEventArgs e)
{
    if (e.Item.ItemType != ListItemType.AlternatingItem && e.Item.ItemType != ListItemType.Item) return;

    ImageButton ib = e.Item.Cells[YourIndex].FindControl("ibDelete") as ImageButton;
    ib.Attributes["onclick"] = "javascript:return confirmerSupprimer()";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM