选择使用jQuery的DropDownList值时,RangeValidator控件不工作 [英] RangeValidator not working when selecting DropDownList value using jQuery

查看:97
本文介绍了选择使用jQuery的DropDownList值时,RangeValidator控件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了我在更新的中间具有的 DropDownList的和的 RangeValidator控件的分配给它。该数据势必对的Page_Load下拉。该值从数据库中,因此每个项目的值属性设置为项目的DB中的唯一ID检索。

在RangeValidator控件看起来是这样的:

 < ASP:RangeValidator控件ID =ddRangeValidator=服务器的ControlToValidate =ddMenu的ErrorMessage =请选择范围值MinimumValue =1MaximumValue =100000 类型=整数> * LT; / ASP:RangeValidator控件>

我有自动填充jQuery的这个值的方法例如。

  $(#ddMenu)VAL(一个选项)。

这不过的工作,当我尝试发布范围验证失败的页面。然后,即使我手动选择该值,或选择它仍然不会验证另一个有效的价值。使它验证的唯一方式是选择非有效值,然后重新选择一个有效的。

任何想法?

更新

下面是数据绑定code:

 私人小组的Page_Load(BYVAL发件人为System.Object的,BYVAL E上System.EventArgs)把手MyBase.Load,Me.Load    如果没有Page.IsPostBack然后
        昏暗的DS作为新的数据集()
        昏暗myDbObject作为新myDbObject()
        DS = myDbObject.ToDataSet()//从数据库中获取的所有对象        //存储结果的临时视图过滤
        昏暗的DV作为数据视图
        的dv =新数据视图(ds.Tables(0),将isLive =真,标识,DataViewRowState.CurrentRows)        昏暗我为整数= 0
        ddMenu.Items.Add(选择价值)
        ddMenu.Items.Item(0)。价值= 0        //从过滤列表中的所有对象添加到下拉菜单
        对于i = 0到dv.Count - 1
            随着ddMenu.Items
                //添加一个新项
               。新增(dv.It​​em(I).Item(姓名))
                //设置Value属性为对象的唯一ID
               .Item第(i + 1)。价值= dv.It​​em(ⅰ).Item(ID)
            结束与
        下一个
    万一万一


解决方案

原来,这是我的页面加载的问题两次... ...所以现在的问题将被追查,为什么它加载的两倍!

I inherited a site which I am in the middle of updating which has a DropDownList and a RangeValidator assigned to it. The data is bound to the dropdown on Page_Load. The values are retrieved from the database so the value property of each item is set to the unique ID of the item in the DB.

The RangeValidator looks something like:

<asp:rangevalidator id="ddRangeValidator" runat="server" ControlToValidate="ddMenu" ErrorMessage="Please select value in range" MinimumValue="1" MaximumValue="100000" Type="Integer">*</asp:rangevalidator>

I have a method which automatically populates this value in jQuery e.g.

$("#ddMenu").val("An Option");

This works, however, when I try to post the page the range validation fails. Then even if I manually select that value, or select another valid value it still won't validate. The only way to make it validate is to select non-valid value and then re-selecting a valid one.

Any ideas?

Update

Here is the data binding code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load

    If Not Page.IsPostBack Then
        Dim ds As New DataSet()
        Dim myDbObject As New myDbObject()
        ds = myDbObject.ToDataSet() // retrieves all objects from the database

        // store the results in a temporary view to filter
        Dim dv As DataView
        dv = New DataView(ds.Tables(0), "IsLive = True", "ID", DataViewRowState.CurrentRows)

        Dim i As Integer = 0
        ddMenu.Items.Add("Select a value")
        ddMenu.Items.Item(0).Value = 0

        // add all objects from filtered list into drop down menu
        For i = 0 To dv.Count - 1
            With ddMenu.Items
                // add a new item
               .Add(dv.Item(i).Item("Name")) 
                // set the Value property as unique ID of object
               .Item(i + 1).Value = dv.Item(i).Item("ID")
            End With
        Next
    End If

End If

解决方案

Turns out it was an issue with my page loading twice...so now the issue is going to be tracking down why it is loading twice!

这篇关于选择使用jQuery的DropDownList值时,RangeValidator控件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆