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?
 
AbebeDemekeConnect With a Mentor Author 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
 
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
All Courses

From novice to tech pro — start learning today.