简体   繁体   English

回发后如何在页面加载中触发datalist_ItemCommand?

[英]How to fire datalist_ItemCommand in page load after postback?

Is it possible to fire datalist_ItemCommand function in page load after post back. 回发后是否可以在页面加载中触发datalist_ItemCommand函数。 It doesn't make sense but I need to achieve this. 这没有道理,但我需要实现这一目标。

Here is the scenerio: I have datalist control and it loaded with some person data. 这是Scenerio:我具有datalist控件,并装有一些人员数据。 It has got a delete button in itemTemplate . 它在itemTemplate有一个删除按钮。

<ItemTemplate>
   <tr>
      <td><%# Eval("Name") %></td>
      <td><%# Eval("EMail") %></td>
      <td align="center"><asp:LinkButton ID="btnDelete" runat="server" CommandName="delete" CommandArgument='<%#Eval("id") %>' OnClientClick="confirmMe('My Program title','Are you sure ?','Yes', 'No', 'datalist1_ItemCommand'); return false;"></asp:LinkButton></td>
    </tr>
</ItemTemplate>

When delete button clicked, custom modal box showing and wait for user response. 单击删除按钮后,将显示自定义模式框并等待用户响应。 If user click yes in modal box then itemCommand function should be fired. 如果用户在模式框中单击“是”,则应触发itemCommand函数。 That's why you see datalist_ItemCommand function in OnClientClick attribute. 这就是为什么您在OnClientClick属性中看到datalist_ItemCommand函数的原因。

Here is JS : 这是JS:

function confirmMe(title, content, button_ok, button_no, asp_control) {

    swal({
        title: title,
        text: content,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#8dc63f",
        confirmButtonText: button_ok,
        cancelButtonText: button_no,
        closeOnConfirm: false,
        closeOnCancel: true
    },
    function (result) {

        if (result === true)
            __doPostBack(asp_control, '');
    });
}

Just call _doPostBack with appropriate id when accepting from modal, Example here 从模态接受时,只需使用适当的ID调用_doPostBack, 此处为示例

function deleteItem(uniqueID, itemID) {
    //Show dialog here
        //on accept call __doPostBack(uniqueID, ''); than close modal
        //on cancel close modal
    return false
}

and call this method on client click 并在客户端单击时调用此方法

OnClientClick="javascript:return deleteItem(this.name, this.alt);"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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