[英]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('Remittance Confirmation','Are you sure you want to update the status?.');setTimeout('__doPostBack(\'gridView$ctl02$ddlTransactionList\',\'\')', 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.