简体   繁体   中英

Popup JQuery modal on dropdownlist selectedindexchanged event

I have a requirement to do some logic execution upon change of dropdownlist value. 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. 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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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