0

I have a asp dropdownlist <asp:DropDownList ID="ddIndProvince" data-style="btn-default" CssClass="form-control input" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddIndProvince_SelectedIndexChanged" TabIndex="8"></asp:DropDownList> On Page load event I inserted "--Select--" item at index 0. Now I am facing problem while I am validating it with bootstrap validator. Its returning valid for "--Select--" item. like below image. enter image description here

How I can validate this.Below us my current script

<script type="text/javascript">
    $(document).ready(function () {          
             $('#form1').bootstrapValidator({
                container: '#messages',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {                   
                    <%=ddIndProvince.UniqueID%>:{
                        validators:{
                            notEmpty:{
                                messages:'please select province'
                            }
                        }
                    }                              
                }   
            });
        });         
    </script>

1 Answer 1

1

bootstrapValidator is validating the value attribute of the <option> tag in your html markup.

Your javascript code is correct. What you need to do is make sure, the value attribute is empty:

Change your markup from:

<option value="Something is in here">--Select--</option>

To:

<option value="">--Select--</option>

Do this in your Page_Load method:

protected void Page_Load(object sender, EventArgs e)
{
    /*...*/

    //Insert new Item at Index 0 with text "--Select--" and no value
    ddIndProvince.Items.Insert(0, new ListItem("--Select--", String.Empty));
    ddIndProvince.SelectedIndex = 0;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.