我想在服务器端显示asp.net中的确认框:
我想从服务器端调用它,因为我必须从服务器端获取客户消息。我使用以下代码
string str = "Are you sure, you want to Approve this Record?";
ClientScript.RegisterStartupScript(typeof(Page), "Popup", "return confirm('" + str + "');",true);
// More code ....
现在它显示弹出窗口,无论我点击什么,无论是“ok”还是“Cancel”,我的代码都在执行。
如果用户在确认框中选择“取消”,请告诉我如何限制执行代码。
答案 0 :(得分:6)
检查出来:
背后的代码:
string str = "Are you sure, you want to Approve this Record?";
this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + str + "');", true);
<强> ASPX:强>
function ConfirmApproval(objMsg)
{
if(confirm(objMsg))
{
alert("execute code.");
return true;
}
else
return false;
}
答案 1 :(得分:1)
检查以下示例代码。
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="btnOK" runat="server" Text="OK" onclick="btnOK_Click" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="lblID" PopupControlID="pnlConfirmation">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlConfirmation" runat="server" Style="background-color: #D4D0C8;
border: 2px solid black; width: 300px; height: 100px;">
<asp:Label ID="lblID" runat="server"></asp:Label>
<table cellpadding="2" cellspacing="2" width="100%">
<tr>
<td>
Your confirmation message here.
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnOK1" runat="server" Text="OK" onclick="btnOK1_Click" /> <asp:Button ID="btncancel"
runat="server" Text="Cancel" onclick="btncancel_Click" />
</td>
</tr>
</table>
</asp:Panel>
在服务器端.....
protected void btnOK_Click(object sender, EventArgs e)
{
//some code here.
//then show modal popup
ModalPopupExtender1.Show();
}
protected void btnOK1_Click(object sender, EventArgs e)
{
//If ok some code here to execute
ModalPopupExtender1.Hide();
}
protected void btncancel_Click(object sender, EventArgs e)
{
//hide modal popup
ModalPopupExtender1.Hide();
}
http://forums.asp.net/t/1499789.aspx?confirmation+popup+from+server+side