[RESOLVED] onclientClick before OnServerClick

hi,

 i would like to do the validation work using javascript or jquery in onclientclick and then show blockUI , next page using server click.

but, i have a captcha validation in server click and i do'nt know how to validate the captcha in jquery or javascript.

    protected void btnRegister_Click(object sender, EventArgs e)
    {        
        lblMessage.Text = "";
        if (Page.IsValid)
        {
            if (txtUserName.Text == "")
            {
                lblMessage.Text = "نام کاربری را وارد نمائید";
                txtUserName.Focus();
                return;
            }
            if (!BLL.IsStrictPassword(txtPassword.Text))
            {
                lblMessage.Text = "طول کلمه عبور حداقل باید 5 کاراکتر باشد";
                txtPassword.Focus();
                return;
            }
            if (ddlYear.Text == "<سال>" || ddlMonth.Text == "<ماه>" || ddlDay.Text == "<روز>")
            {
                lblMessage.Text = "لطفا تاریخ تولدتان را وارد نمائید";
                return;
            }
            if (!chk_Low.Checked)
            {
                lblMessage.Text = "برای عضویت می بایست قوانین سایت را بپذیرید";
                return;
            }
            if (txtSecurityCode.Text == String.Empty)
            {
                lblMessage.Text = "کد امنیتی را وارد نکرده اید";
                txtSecurityCode.Focus();
                return;
            }
            secCode.ValidateCaptcha(txtSecurityCode.Text);
            if (!secCode.UserValidated)
            {
                lblMessage.Text = "کد امنیتی نادرست وارد شده است";
                return;
            }
            try
            {
//some code
}
}

I don't know the answer, but why don't you use the ASP.NET validation controls? They run on the client and will handle much of this for you.

At the end of your client validation function defined in the button's "onclientclick" attribute either return true (validation success, go on with the postback) or false (validation not successful, halt all other javascript functions)

actually if you use the asp.net validation controls you will be using JavaScript automatically because they will generate javascript validation code and insert it to your pages html code at runtime.

hi

thanks for all replys.

but my main problem is captcha validation.as i said before,i have a piece code in server click that validate the captcha.

i use the asp.net validation for other controls in the page,but what i do for captcha, or how to communicate between client and server click.

thanks a lot


thoughts on "[RESOLVED] onclientClick before OnServerClick"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>