【问题标题】:Call jquery modal popup from asp.net dropdownlist change从 asp.net 下拉列表更改调用 jquery 模式弹出窗口
【发布时间】:2014-06-04 15:46:47
【问题描述】:

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

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

    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);
    }

谢谢

【问题讨论】:

    标签: c# javascript jquery asp.net


    【解决方案1】:

    我认为 ASP.NET 创建的 javascript 与您添加到下拉列表中的 onchange 事件(onchange="return .... ")之间存在冲突,因此它忽略了回发的调用。

    我会先在前端尝试这样的事情:

    // 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
    }
    

    如果这有帮助,请告诉我们。

    【讨论】:

    • 唯一的问题是这段代码在用户控制中,而不是在主页上。
    • 与我发布的答案有关的问题是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多