required field validation problem

I have a page that contains a form and i have addred required field validators to some of the fileds. In addtion when the page is submitted (user clicks the submit button) I wanted a comfirmation window to come so, in the Page_Load method I have ,
 this.btnSmt.Attributes.Add("onclick", "return confirm(\"Comfirm that you want the record to be Created\",\"Yes\",\"No\");"); //attaching dialog window

Now the problem is the client side validation (required field validator) will not work after adding this feature. But if I comment out the above line of code, the validation works.

The issue seems like the page is submitted without being validated.

any idea pleas
         
AbebeDemekeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Hello AbebeDemeke,

Try :


this.btnSmt.Attributes.Add("onclick", "return confirm(\"Comfirm that you want the record to be Created\");"); //attaching dialog window

Open in new window

0
AbebeDemekeAuthor Commented:
leakim971, did u read my question well?
u just copied and past my code?

I have that code and it works fine. the problem is it seems to get executed before validation
0
leakim971PluritechnicianCommented:
>u just copied and past my code?
Not really, I removed \"Yes\",\"No

Because you said :
>Now the problem is the client side validation (required field validator) will not work after adding this feature

I think it's because javascript confirm don't have this parameter.

Did you try to use : onSubmit in your form tag :


<FORM id="myform" name="myform" onSubmit="return confirm('Comfirm that you want the record to be Created');" method="post" runat="server">

or 

myform.Attributes.Add("onSubmit",return confirm(\"Comfirm that you want the record to be Created\");");

Open in new window

0
AbebeDemekeAuthor Commented:
I have found the solution any way. the problem was not the yes and no things rather issue of the validation web controls and the java script used for confirmation I solved like the following
 <asp:Button ID="btnSmt" runat="server" Text="ADD Record" OnClick="btnSmt_Click" BackColor="ButtonFace"
                    Font-Bold="False" Font-Names="Arial" Font-Overline="False" OnClientClick="if (Page_ClientValidate()){ return confirm('Confirm that you want this record be created')}"
                    CausesValidation="false" />

forget the other attributes and focus on the OnclientCilck and CausesValidation attributes
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.