简体   繁体   English

在下拉列表selectedIndexchanged事件上弹出JQuery模式

[英]Popup JQuery modal on dropdownlist selectedindexchanged event

I have a requirement to do some logic execution upon change of dropdownlist value. 我要求在dropdownlist值更改时执行一些逻辑执行。 Before executing the logic i need to take user confirmation and then call server side method to complete the process. 在执行逻辑之前,我需要进行用户确认,然后调用服务器端方法以完成该过程。 Not sure How to call server side method based on modal popup confirmation response from user. 不确定如何根据用户的模式弹出窗口确认响应调用服务器端方法。 So if user confirms with Yes button on the modal popup server side code should be called otherwise do nothing. 因此,如果用户通过模式弹出服务器端的“是”按钮确认,则应调用代码,否则不执行任何操作。

Here is the code i have . 这是我的代码。 Server side does not get called upon modal popup confirmation. 在模式弹出确认时不会调用服务器端。

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>

The server side code is below: 服务器端代码如下:

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

Check the generated HTML code of your page and have a closer look on your dropdown. 检查页面生成的HTML代码,并仔细查看下拉菜单。 It should look like this: 它看起来应该像这样:

<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">

The problem is that you "return" the outcome of your PopupDialog so that the __doPostback function (AutoPostBack) has no chance of getting called. 问题是您“返回”了PopupDialog的结果,因此__doPostback函数(AutoPostBack)没有机会被调用。 My advice: Only return if the user rejects the change. 我的建议:仅当用户拒绝更改时返回。 If the user agrees dont return anything. 如果用户同意,请勿返回任何内容。

Edit (forgot post the solution code) 编辑(忘记发布解决方案代码)

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

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

相关问题 下拉列表 selectedindexchanged 事件未触发 - Dropdownlist selectedindexchanged event is not firing DropDownList的SelectedIndexChanged事件未触发 - SelectedIndexChanged event of DropDownList is not fired jQuery是否可以在DropDownList上触发服务器端“ selectedIndexChanged”事件? - Can Jquery trigger a server-side “selectedIndexChanged” event on a DropDownList? 未在SelectedIndexChanged事件上加载级联Dropdownlist - Cascading Dropdownlist not loaded on SelectedIndexChanged Event checkbobx检查下拉列表的SelectedIndexChanged()事件 - SelectedIndexChanged() event of a dropdownlist on a checkbobx checking 在gridview rowdatabound事件中调用dropdownlist selectedindexchanged事件? - call dropdownlist selectedindexchanged event in gridview rowdatabound event? 在selectedindexchanged事件中设置下拉列表选择的值? - Set dropdownlist selected value inside selectedindexchanged event? 为什么DropDownList.SelectedIndexChanged事件不会触发? - Why DropDownList.SelectedIndexChanged event does not fire? 如何加快Dropdownlist SelectedIndexChanged事件 - How to speed up Dropdownlist SelectedIndexChanged event 停止DropDownList SelectedIndexChanged事件在FormView命令上触发 - Stop DropDownList SelectedIndexChanged Event firing on FormView command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM