我需要在更改下拉列表值时执行一些逻辑执行。在执行逻辑之前,我需要进行用户确认,然后调用服务器端方法来完成该过程。不确定如何根据用户的模态弹出确认响应调用服务器端方法。因此,如果用户在模态弹出服务器端确认是按钮,则应调用端代码,否则不执行任何操作。
这是我的代码。在模态弹出确认时不会调用服务器端。
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);
}
答案 0 :(得分:0)
检查生成的网页HTML代码,仔细查看下拉列表。它应该是这样的:
<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">
问题是你“返回”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>