I had to do a JavaScript confirmation before I perform the post back on a web form. What I have done is just call button.attributes.add("onClick", -- ) and added the confirmation.
It worked fine and showed the popup and did the post back if I clicked on the OK button. But if I have implemented some validations on the fields they doesn't fire them if the validation fails. For example if there is a required field validator the post back happens even without the values for that required field.
what I want is to do the validation and then do the post back. Luckily I've found a solution at http://forums.asp.net/t/963412.aspx?PageIndex=1 by sukdeb.
It worked fine for me. I have added the script as button.attributes.add("onClick", -- ) and it works fine for me even with the "onClick" event.
It worked fine and showed the popup and did the post back if I clicked on the OK button. But if I have implemented some validations on the fields they doesn't fire them if the validation fails. For example if there is a required field validator the post back happens even without the values for that required field.
what I want is to do the validation and then do the post back. Luckily I've found a solution at http://forums.asp.net/t/963412.aspx?PageIndex=1 by sukdeb.
function Validate() { var yes=confirm("Update this application?"); if(yes) { Page_ClientValidate(); return Page_IsValid; } return false; }
<asp:button runat="server" text="Button" onclientclick="return Validate()">Pasted from http://forums.asp.net/t/963412.aspx?PageIndex=1
It worked fine for me. I have added the script as button.attributes.add("onClick", -- ) and it works fine for me even with the "onClick" event.
wish u the same
ReplyDelete