javascriptc#asp.nettwitter-bootstrapjqbootstrapvalidation

How to submit form with Bootstrap Validator


I am using http://bootstrapvalidator.com/ with visual studio in bootstrap asp.net project. Problem I am having that I can never get validate button to actually validate like it does in examples, it validates fine when I start typing into textbox, but never validates when I click on button following examples.

Another issue is I don't know how to call my c# method which will get value from textbox after validation was successful, I can call my method on button click, but I want it to happen just after validation was successful .

What I am looking for is simple example how to make submit button validate fields and then call my c# method which will read values from inputs.

I been unable find even single example online , and I dont know much about javascript.

Here is some testing code I have

 <div class="form-group" id="nameEmail2">
        <div class="form-group">
            <label for="inputContactName" class="col-sm-5 control-label">Contact Name </label>
            <div class="col-sm-7">
                <input type="text" class="form-control" name="fullName1" id="TextBox1" placeholder="Contact Name" maxlength="50"/>
            </div>
        </div>
        <div class="form-group">
            <label for="inputContactEmail" class="col-sm-5 control-label">Contact Email <b>*</b></label>
            <div class="col-sm-7">
                <input type="text" class="form-control" name="email1" id="TextBox2" placeholder="Contact Email" maxlength="50"/>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-5 col-sm-offset-3">
                <button type="submit" runat="server" onserverclick="submitValidate"  class="btn btn-default">Validate</button>
            </div>
        </div>
        </div>



        <script type="text/javascript">
            $(function () {
                $('#nameEmail2').bootstrapValidator({
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },                        
                    fields: {
                        fullName1: {
                            validators: {
                                notEmpty: {
                                    // enabled is true, by default
                                    message: 'The full name is required and cannot be empty'
                                },
                                stringLength: {
                                    enabled: true,
                                    min: 8,
                                    max: 40,
                                    message: 'The full name must be more than 8 and less than 40 characters long'
                                },
                                regexp: {
                                    enabled: false,
                                    regexp: /^[a-zA-Z\s]+$/,
                                    message: 'The full name can only consist of alphabetical, number, and space'
                                }
                            }
                        },
                        email1: {
                            validators: {
                                emailAddress: {
                                    message: 'The value is not a valid email address'
                                }
                            }
                        }
                    }
                });
            });
        </script>

I have removed most of asp objects and almost nothing runs at server any more, but that didnt help much here is my codebehind method

protected void submitValidate(object sender, EventArgs e) 
{
    string contactName = Request.Form["fullName1"];
    string email = Request.Form["email1"];
    System.Diagnostics.Debug.Write("test",email);
}

Solution

  • Found an answer to my own question http://thuyvk.com/article/validate-form-su-dung-bootstrapvalidator-cho-website-aspnet-224 Be careful with google translate, will translate code into some random html code