【问题标题】:Popup JQuery modal on dropdownlist selectedindexchanged event在下拉列表 selectedindexchanged 事件上弹出 JQuery 模式
【发布时间】:2014-06-04 19:54: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>

服务器端代码如下:

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

【问题讨论】:

  • 您能否将完整的代码发布到您的 asp.net 页面?一个简单的解决方案是确保 [Yes] 按钮是具有 runat="Server" 值的 ASP.NET 对象...发布您的 asp.net 代码,我可以帮助您。

标签: c# javascript jquery asp.net jquery-ui


【解决方案1】:

检查您的网页生成的 HTML 代码,并仔细查看您的下拉菜单。它应该是这样的:

<select name="gridView$ctl02$ddlTransactionList" onchange="return PopupDialog(&#39;Remittance Confirmation&#39;,&#39;Are you sure you want to update the status?.&#39;);setTimeout(&#39;__doPostBack(\&#39;gridView$ctl02$ddlTransactionList\&#39;,\&#39;\&#39;)&#39;, 0)" id="gridView_ddlTransactionList_0">

问题在于您“返回”了 PopupDialog 的结果,因此 __doPostback 函数 (AutoPostBack) 没有机会被调用。我的建议:只有在用户拒绝更改时才返回。如果用户同意不返回任何东西。

编辑(忘记发布解决方案代码)

<asp:DropDownList ID="ddlTransactionList" AutoPostBack="True"  OnSelectedIndexChanged="ddlTransactionList_SelectedIndexChanged" onchange="if(! PopupDialog('Remittance Confirmation','Are you sure you want to update the status?.')){return false;}"  runat="server"></asp:DropDownList>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多