I am new to asp.net/C# .I am trying to create a web application.
Below is my requirement.
I am trying to save a record on button click. Before saving the rec
One of the workaround can be to store the TRUE / FALSE flag in control that has the attribute runat="server", depending on the choice made by user (Yes / No). And then at the backend, you can check for the value of this control.
Use AJAX toolkit with modalpopupextender.
<cc1:modalpopupextender id="ModalPopupExtender1" runat="server" cancelcontrolid="ButtonNo" okcontrolid="ButtonYes" popupcontrolid="PNL" targetcontrolid="UrSaveButton">
</cc1:modalpopupextender>
<asp:Panel ID="PNL" runat="server" Style="display: none; width: 200px; background-color: #000099; border-width: 2px; border-color: Black; border-style: solid; padding: 20px;">
<span style="color: White; font-weight: bold">Record already exist.Do you want to proceed?</span>
<br />
<br />
<div style="text-align: right;">
<asp:Button CssClass="tbl_blue" ID="ButtonYes" runat="server" CausesValidation="false" EnableTheming="false" Text="YES" />
<asp:Button CssClass="tbl_blue" ID="ButtonNo" runat="server" CausesValidation="false" EnableTheming="false" Text="NO" />
</div>
</asp:Panel>
You can Customize it as you want.
You can do this in many ways:
One is place a button on the page, make its display:none and when confirm is true, trigger its click with js.
Like in aspx
<asp:Button runat="server" ID="btnSaveData"
onClick="btnSaveData_Click" style="display:none;" />
in client side make a js function for calling confirmation dialog box, like
function ConfirmSave()
{
if(confirm('Record already exist.Do you want to proceed?')
{
jQuery("[ID$=btnSaveData]").click();
}
}
in Code Behind
Your code check in some event handler
if (check == true)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script",
"ConfirmSave();", true);
}
bthSaveData click handler for saving data.
protected void btnSaveData_Click(object sender, EventArgs e)
{
// Code for your saving.
}
you can take a look at the this link http://www.codeproject.com/Articles/8173/A-Simple-ASP-NET-Server-Control-Message-Box-Confir.
And more over you can create your own custom confirmation box.
You can use confirm box in JS like this
var ans = confirm ('Record already exist.Do you want to proceed?');
if(ans==true)
{
}
else
{
}
Secondly, to get the response in code behind, you can store the Yes/No value into a hidden field e.g.
document.getElementById('<%= hiddenField.ClientID %>').value = ans;