Is it possible to add code to this control? I am creating a mock credit card app and am using some of the validation controls(required and regular expession). When the user clicks "buy" and the info is not entered I have a Validation Summary popup box that shows up indicating that the fields need to be filled out correctly. After clicking "OK", the confirmation box pops up asking the user "Are you sure you want to purchase this software?". How to do I change this so the confirmation popup shows up after the validation is correct?
Thanks
Hi ts2527,
Based on my understanding, I think your concern is:
1. If the input is invalid, ValidationSummary control will pop up a prompt window.
2. If the input is valid, pop up a confirm window to confirm if user really want to continue. If user click "no", nothing happen. Otherwise, do something on the server side.
By the way, pop up a confirm dialog after ValidationSummary alert window is useless (for client validation), because the page is invalid and the request will not send to the server.
Based on my test, I implement it by RegisterStartupScript instead of extending the confirmationbuttonextender control. I hope it is acceptable to you. Following is the demo code.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function ConfirmBuy()
{
var result = confirm('Are you sure you want to purchase this software?');
if (result)
{
document.getElementById('Button2').click();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Style="position: static"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Style="position: static" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Style="display:none" Text="" />
</ContentTemplate>
</asp:UpdatePanel>
<input id="Hidden1" type="hidden" runat="server" />
</form>
</body>
</html>
*********** codebehind file
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUpScript", "ConfirmBuy()", true);
}
protected void Button2_Click(object sender, EventArgs e)
{
//do something here
}
No comments:
Post a Comment