0

我有一个奇怪的问题,下拉框 selectedIndex 在回发时总是设置为 0。我不会不小心在我的代码中重新绑定它。事实上,我已经在 page_load 事件的第一行放置了一个断点,并且该值已经设置为零。下拉列表在我的项目的母版页中,我不知道这是否会有所不同。我没有在我的内容持有者中引用控件。

如果我设置我的 autoPostBack = 'true' 页面工作正常。我不必更改任何代码,并且 selectedIndex 会被维护。我也尝试过设置 enableViewState on 和 off 并没有什么区别。在这一点上,我正在抓住稻草来弄清楚发生了什么。我以前从来没有遇到过这个问题。

这是我的 page_load 事件中的代码。

        If CartEstablished Then
            txtCustNum.Visible = False
            btnCustSearch.Visible = False
            lblCustNum.Visible = True
            ddlSalesType.Visible = False
            lblSalesType.Visible = True
            ddlTerms.Visible = False
            lblTerms.Visible = True

            lblTerms.Text = TermsDescription
        Else
            txtCustNum.Visible = True
            btnCustSearch.Visible = True
            lblCustNum.Visible = False

            lblSalesType.Visible = False
            ddlSalesType.Visible = True
            lblTerms.Visible = False
            ddlTerms.Visible = True
        End If

        If Page.IsPostBack Then
             GetUIValues()
        Else

             LoadTermCodes()
        End If

LoadTermCodes 是我绑定导致我出现问题的下拉列表的地方。

4

5 回答 5

1

你确定你在做回发而不是刷新吗?如果没有更多关于问题或代码块的上下文,很难为您提供帮助。

于 2008-09-16T15:22:22.317 回答
0

I'm finding the same problem... in my case, the dropdownlist is filled by a javascript function after another dropdownlist onchange client event. On PageLoad, the 2nd dropdownlist has lost all its items and so its selectedIndex turns to 0. Is there any way of preventing this?

于 2008-11-05T10:21:32.200 回答
0

这可能是找错了树,但过去让我抓狂的几件事让我摸不着头脑:

  • 将输入元素命名为重复/保留的单词(考虑“名称”、“方法”、“重置”等)
  • 将表单元素物理地置于要提交的表单之外

我发现当所有的逻辑调试都没有结果时,我自己的愚蠢有时会造成像这样浪费时间的“神秘”错误。

于 2008-09-16T15:25:46.160 回答
0

您在页面生命周期的哪个阶段绑定下拉列表?如果您在 page_init 中进行绑定,它应该可以工作,如果您在 page_load 中进行绑定,请确保将 !IsPostBack 包裹在绑定命令周围。

如果您发布有问题的代码,则更容易进行故障排除。

于 2008-09-16T15:32:20.450 回答
-1

这可能只是一个语法错误,但不应该

 If Page.IsPostBack Then
             GetUIValues()
        Else

看起来像这样

  If  NOT Page.IsPostBack Then
         GetUIValues()
    Else
于 2008-09-16T17:24:33.397 回答