0

我希望在删除记录之前向用户填充一个弹出窗口我尝试过OnClientClick以使用 JavaScript/jQuery 处理它但没有成功

错误

Type 'System.Web.UI.WebControls.HyperLinkField' does not have a public property named 'OnClientClick'.

控制

 <asp:HyperLinkField  OnClientClick="return confirm('Are you sure you would like to delete the selected landing page?')" datanavigateurlfields="id"    datanavigateurlformatstring="ViewLandingPages.aspx?id={0}&delete=yes"   HeaderText="Delete"  Text="Delete" />

编辑:还尝试添加一个 (用于使用 jquery 处理它)但没有成功

4

4 回答 4

2

请注意,它没有在其 members 中声明OnClientClick事件。

尝试NavigateUrl像这样设置属性:

NavigateUrl='<%# "javascript:return confirm('Are you sure you would like to delete the selected landing page?')" %>'

更新

也尝试设置DataNavigateUrlFormatString这样的:

DataNavigateUrlFormatString="{0}"
于 2012-09-27T15:06:44.207 回答
2

您可以使用 <asp:Button/>,<asp:LinkButton/><asp:ImageButton/>来处理客户端和服务器端的点击事件。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
    <Columns>
       <!--- Other columns/Fields -->
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton 
                    ID="LinkButton1" 
                    runat="server" 
                    OnClientClick='return confirm("Are you sure to delete a record?")'
                    CommandName="Delete">Delete</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
于 2012-09-27T15:22:21.710 回答
0

在我的项目中,我确实喜欢这样,我显示一个 div 进行确认,如下所示

<div id="dvDeleteCategory" title="Delete Category">
    <h5>
        Are you sure you wont to delete this category !!!</h5>
</div>

<script type="text/javascript">
    $(function () {       
        $(".lnkDelete").button();
        $("#dvDeleteCategory").dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            resizable: false,
            height: 250
        });

        $(".lnkDelete").click(function (e) {
            e.preventDefault();
            var trargeturl = $(this).attr('href');
            $("#dvDeleteCategory").dialog({
                buttons: {
                    "Delete": function () {
                        window.location.href = trargeturl;
                    },
                    "Cancle": function () {
                        $(this).dialog('close');
                    }
                }
            });
            $("#dvDeleteCategory").dialog('open');
        });
    });
</script>

我想这会帮助你..

于 2012-09-27T15:25:10.013 回答
0

使用模板字段解决了我的问题;)

<asp:TemplateField HeaderText="Delete" ShowHeader="False">
  <ItemTemplate>
     <a onclick="return confirm('Are you sure to delete a record?')" href="ViewLandingPages.aspx?delete=yes&id=<%# Eval("id") %>">Delete</a>
   </ItemTemplate>
</asp:TemplateField>
于 2012-09-27T16:36:14.170 回答