文档就绪函数bootstrapValidator运行代码在button_click on Postback

时间:2016-03-24 18:54:03

标签: javascript asp.net buttonclick document-ready autopostback

我有验证码:(它工作正常)

$(document).ready(function () {
            $('#mainform').bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    ku: {
                        validators: {
                            notEmpty: {
                                message: 'test2'
                            },
                            stringLength: {
                                min: 11,
                                message: 'test'
                            }
                        }
                    }


                }
            });
        });

但是在带有AutoPostBack="true"的DropDownList中,我改变了选择的项目,这个JS代码运行:

Protected Sub button_Click(sender As Object, e As EventArgs) Handles button.Click

但是,这会在网站上为每个asp:buton运行点击事件。

我该如何防止这种情况?

我只想在点击此按钮时运行button_Click

下拉列表代码:

<asp:DropDownList class="form-control" ID="produkt" runat="server" OnSelectedIndexChanged="produkt_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>



   Protected Sub produkt_SelectedIndexChanged(sender As Object, e As EventArgs) Handles produkt.SelectedIndexChanged
        data_ofertowania.Text = Request.Form(data_ofertowania.UniqueID)
        Dim myConn As SqlConnection
        Dim myCmd As SqlCommand
        Dim myReader As SqlDataReader
        myConn = New SqlConnection(connStr)
        myCmd = myConn.CreateCommand
        myCmd.CommandText = "SELECT '' as podprodukt UNION SELECT DISTINCT [nazwa_podprodukt] FROM [dbo].[slo_produkt] WHERE [active]='True' and grupa='" & grupa_produktow.SelectedValue & "' and nazwa_produkt='" & produkt.SelectedValue & "'"
        myConn.Open()
        myReader = myCmd.ExecuteReader()
        podprodukt.DataSource = myReader
        podprodukt.DataValueField = "podprodukt"
        podprodukt.DataTextField = "podprodukt"
        podprodukt.DataBind()
        myConn.Close()
    End Sub

0 个答案:

没有答案