从asp.net下拉列表更改调用jquery模式弹出

本文关键字:jquery 模式 调用 asp net 下拉列表 | 更新日期: 2023-09-27 18:06:36

我需要在更改下拉列表值时执行一些逻辑。在执行逻辑之前,我需要接受用户确认,然后调用服务端方法来完成该过程。不确定如何根据用户的模式弹出确认响应调用服务器端方法。因此,如果用户在模态弹出窗口上确认是按钮,服务器端代码应该被调用,否则什么也不做。

这是我的代码。在模式弹出窗口确认时,服务器端不会被调用。

    function PopupDialog(title, text) {
        var div = $('<div>').html('<br>'+text).dialog({
        title: title,
        modal: true,
        height: 190,
        width: 320,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
            },
            "No": function () {
                $(this).dialog('close');
            }
         }
         });
         return true;
      };

     <asp:GridView runat="server" ID="grdTransactions" SkinID="gridviewskin"  
        AllowSorting="true" AllowPaging="true" PageSize="30" Width="100%" 
        OnRowDataBound="grdTransactions_RowDataBound"
        OnDataBound="grdTransactions_DataBound"  
        OnSelectedIndexChanged="grdTransactions_SelectedIndexChanged">
       .............
    <asp:TemplateField Visible="true" HeaderText="Status" >
        <ItemTemplate>
            <asp:Label runat="server" ID="lblStatus"  Visible="False" Text='<%# ShowStatus( Container.DataItem ) %>' />
            <asp:DropDownList ID="ddlTransactionList" AutoPostBack="True"  OnSelectedIndexChanged="ddlTransactionList_SelectedIndexChanged" onchange="return PopupDialog('Remittance Confirmation','Are you sure you want to update the status?.');"  runat="server"></asp:DropDownList>
            <br/>
        </ItemTemplate>
    </asp:TemplateField>

   **Server Side Code --**
    protected void ddlTransactionList_SelectedIndexChanged(object sender, 
          EventArgs e)
    {
        //Your Code
        if (OnDataChanged != null)
            OnDataChanged(sender, e);
    }

谢谢

从asp.net下拉列表更改调用jquery模式弹出

我认为ASP创建的javascript之间存在冲突。. NET和onchange事件添加到下拉列表(onchange="return .... . NET ")

我会在前端尝试这样做:

// remove the autopostback & onchange from the ddl definition
<asp:DropDownList ID="ddlTransactionList" runat="server"></asp:DropDownList>
function PopupDialog(title, text) {
    var div = $('<div>').html('<br>'+text).dialog({
    title: title,
    modal: true,
    height: 190,
    width: 320,
    buttons: {
        "Yes": function () {
            $(this).dialog('close');
            return true;
        },
        "No": function () {
            $(this).dialog('close');
        }
    }
});

};

$(document).ready(function(){
    $("<% ddlTransactionList.CLientID %>").change(function(){
        if(PopupDialog('Remittance Confirmation','Are you sure you want to update the status?.')){
            __doPostBack('ddlTransactionList')
        }
    });
});

在代码后面:

public void Page_Load(object sender, EventArgs e)
{
    string parameter = Request["__EVENTARGUMENT"]; // parameter
    // Request["__EVENTTARGET"]; // ddlTransactionList
    // make your call to ddlTransactionList_SelectedIndexChanged() here
}