I am trying to use the confirmbuttonextender, but I only want to show the confirm message if some validation passes. I have a button that calls a javascript function to perform some validation. If validation fails the javascript returns false and would stop the button from submiting. I tried setting the ConfirmOnFormSubmit=true, but when I do this the javascript function doesn't seem to be called. When it is false the confirm message appears, then I click OK, then the javascript is called, but the button still submits even thought the function returned false. Any help would be appreciated, I haven't found any working example.
Thanks,
Matt
My code:
<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" TargetControlID="btnDelete" runat="server"
ConfirmText="Are you sure you want to delete?" ConfirmOnFormSubmit=true ></ajaxToolkit:ConfirmButtonExtender>
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick="DeleteEquipFunction();" />
<script type="text/javascript">
function DeleteEquipFunction()
{
//some validation
return false;
}
</script>
I think, if this case you should not use ConfirmButtonExtender, because AJAX creates a function on init event of page, which is then binded to command button.
Can you change your code like this.
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick="return DeleteEquipFunction();" />
<script type="text/javascript">
function DeleteEquipFunction()
{
//some validation
if(validated) //validated is true
{
return confirm("Are you sure you want to delete?");
}
return false;
}
</script>
Thanks Ritesh.
I wound up following your suggestion and it works good.
I thought the ConfirmOnFormSubmit property was added to the confirmbutton so the confirm would not as the last action before server submission, but it seems to fire before onClientClick, and therefore you can't seem to stop it. I love the Ajax toolkit, but it seems there are some obscure properties of these controls that are not clearly defined on Microsofts website or any book I have found.
No comments:
Post a Comment