Hi beb54,
You can do it by two way.
1) When your IsStock return false then you can show ModalPopup where you can give option Yes or No to confirm user answer. Onclick of Yes call the saving code which you used to save in current code on No just hide ModalPopup so no any action will perform.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.modalBackground
{
background-color: Black;
filter: alpha(opacity=40);
opacity: 0.4;
}
.modalPopup
{
background-color: #FFFFFF;
width: 300px;
border: 3px solid #0DA9D0;
}
.modalPopup .header
{
background-color: #2FBDF1;
height: 30px;
color: White;
line-height: 30px;
text-align: center;
font-weight: bold;
}
.modalPopup .body
{
min-height: 50px;
line-height: 30px;
text-align: center;
font-weight: bold;
}
.modalPopup .footer
{
padding: 3px;
}
.modalPopup .yes, .modalPopup .no
{
height: 23px;
color: White;
line-height: 23px;
text-align: center;
font-weight: bold;
cursor: pointer;
}
.modalPopup .yes
{
background-color: #2FBDF1;
border: 1px solid #0DA9D0;
}
.modalPopup .no
{
background-color: #9F9F9F;
border: 1px solid #5C5C5C;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:LinkButton ID="lnkfake" runat="server"></asp:LinkButton>
<asp:Button ID="btnSave" Text="Save" runat="server" OnClick="Save" />
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:ModalPopupExtender ID="mpe" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkfake"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Confirmation
</div>
<div class="body">
Some products are out of stock your order will be pending ,are you sure you want
to proceed ?
</div>
<div class="footer" align="right">
<asp:Button ID="btnYes" runat="server" Text="Yes" CssClass="yes" OnClick="ConfirmSave" />
<asp:Button ID="btnNo" runat="server" Text="No" CssClass="no" />
</div>
</asp:Panel>
</form>
</body>
</html>
C#
protected void Save(object sender, EventArgs e)
{
if (!isInStock())
{
mpe.Show();
}
else
{
// call saving method
SaveDetails();
}
}
protected void SaveDetails()
{
// your saving code.
}
protected void ConfirmSave(object sender, EventArgs e)
{
mpe.Hide();
// call saving method
SaveDetails();
}
private bool isInStock()
{
// your code based on that you can return true or false
//return true;
return false;
}
VB.Net
Protected Sub Save(sender As Object, e As EventArgs)
If Not isInStock() Then
mpe.Show()
Else
' call saving method
SaveDetails()
End If
End Sub
Protected Sub SaveDetails()
' your saving code.
End Sub
Protected Sub ConfirmSave(sender As Object, e As EventArgs)
mpe.Hide()
' call saving method
SaveDetails()
End Sub
Private Function isInStock() As Boolean
' your code based on that you can return true or false
'return true;
Return False
End Function
Screenshot

2) Add one link button with Onclick Event will be hidden. When your IsStock return false you can call JavaScript confirm message box based on selection yes no you can perform action.
On click of yes just call __doPostBack('<%= LinkButtonId.ClientID %>', 'OnClick'); so it will call the Onclick event of Link button which will save the rest part also add EnableEventValidation="false" in Page Directive.
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function Confirm() {
if (confirm("Do you want to save data?")) {
__doPostBack('<%= btnConfrimSave.ClientID %>', 'OnClick');
} else {
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="btnConfrimSave" runat="server" OnClick = "SaveDetails"></asp:LinkButton>
<asp:Button ID="btnSave" runat="server" OnClick="Save" Text="Save" />
</div>
</form>
</body>
</html>
C#
private bool isInStock()
{
// your code
//return true;
return false;
}
protected void Save(object sender, EventArgs e)
{
if (!isInStock())
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "Confirm();", true);
}
else
{
SaveDetails();
}
}
protected void SaveDetails(object sender, EventArgs e)
{
SaveDetails();
}
protected void SaveDetails()
{
// your saving code.
}
VB.Net
Private Function isInStock() As Boolean
' your code
'return true;
Return False
End Function
Protected Sub Save(sender As Object, e As EventArgs)
If Not isInStock() Then
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "", "Confirm();", True)
Else
SaveDetails()
End If
End Sub
Protected Sub SaveDetails(sender As Object, e As EventArgs)
SaveDetails()
End Sub
Protected Sub SaveDetails()
' your saving code.
End Sub
Screenshot
