RadioButton的状态是不是在回调之间持续存在?

时间:2015-06-09 19:24:57

标签: asp.net vb.net

我有一个如下所示的DataGrid:

<asp:datagrid id="dgICDCodes" runat="server" bodyHeight="300px" CssClass="tblScroll" Width="100%">
    <Columns>
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="clsGridHeaderText"
            HeaderStyle-Wrap="False" HeaderStyle-Width="10%" ItemStyle-Width="10%">
            <HeaderTemplate>
                Select
            </HeaderTemplate>
            <ItemTemplate>
            <asp:RadioButton ID="rbSelect" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Code") %>'
            AutoPostBack="true" />
            </ItemTemplate>
            <HeaderStyle Wrap="False" CssClass="clsGridHeaderText" Width="10%"></HeaderStyle>
            <ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
        </asp:TemplateColumn>
    </Columns>
</asp:datagrid>

在代码隐藏中使用RB的Text属性来设置一个变量,用于在用户选择该行时跟踪该行的唯一Code

用户输入搜索参数后,应用程序会构建列并使用数据库中的结果填充此网格。

当用户选择一行时,会发生这种情况:

  • Page_Load fires
  • IsPostBacktrue
  • 某些逻辑需要重新绑定网格
    • 除了单选按钮外,它会删除所有列,并将它们重新添加到网格
  • 调用另一个方法,将DataGrid的DataSource重新设置为持久性DataTable
  • 在UI上取消选择该行。

某处此单选按钮的已检查状态是丢失或“重写”,但我绝对无法弄清楚在哪里,我想知道它是否与回发性质有关?但是,如果我删除AutoPostBack="true",则单选按钮的行为与预期的不同,并且可以在网格中选择多行。

Web开发新手,所以我真的不知道该怎么做......

编辑添加一些与Page_Load相关的代码:

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

    If Not IsPostBack Then

        Call mfpEnableDisableControls()

        cmdSearch.Attributes.Add("onClick", "return mfpValidate();")
        txtNoOfRecords.Attributes.Add("onBlur", "return mfpIsNoOfRecords(this);")

        Call mfpFillPresumptiveRuleCombo()
        mfpFillTierCombo()

        cmdRefresh.Attributes.Add("onClick", "return mfpIsNoOfRecords(document.forms[0].txtNoOfRecords, true);")

        mInitializeSpread(dgCodes, False, True, True)
        mInitializeSpread(dgCodes_AdditionalTier, False, True)
        mInitializeSpread(dgCodes_AdditionalCompliance, False, True)

        Call mfpLoadData("-1", vbNullString, vbNullString, vbNullString)
        `mfpLoadData executes some stored procedures, puts the results into the DataTables used in mfpBindGrid, and then it calls mfpBindGrid
    Else
            If Request("__EVENTTARGET").StartsWith(dgCodes.Controls(0).Controls(0).UniqueID.Replace("$", ":") & ":") = False Then
                Call mfpBindGrid(False)
            End If

        End If
End Sub

mfpBindGrid

Private Sub mfpBindGrid(ByVal aBlnReloadFromDB As Boolean, Optional ByVal aCurrentPageIndex As Integer = 0)

    mfpFindRadioButton(dgCodes.Controls) 'This just checks which RB was selected and stores a Code in a variable on the form

    mfpInitGridColumns() 'This drops everything after the first column (the RB) and re-adds them

    mFillGridData(mobjDTCodes, dgCodes, Not aBlnReloadFromDB, ViewState, aCurrentPageIndex)
    mFillGridData(mobjDTTierCodes, dgCodes_AdditionalTier, Not aBlnReloadFromDB, ViewState, aCurrentPageIndex)
    mFillGridData(mobjDTPeerCodes, dgCodes_AdditionalCompliance, Not aBlnReloadFromDB, ViewState, aCurrentPageIndex)

    'These methods configure the grids (dgName) based on the DataTable (mobjDTname) and re-set their DataSource to the tables passed.

End Sub

这有点像clusterfsck。基本上是操作顺​​序:

页面加载 - &gt;不回发 - &gt; mfpLoadData() - &gt; BindGrid()

用户点击搜索 - &gt; PageLoad - &gt;回帖 - &gt; BindGrid() - &gt;搜索点击事件火灾 - &gt; mfpLoadData() - &gt; BindGrid()

用户选择行 - &gt; PageLoad - &gt;回帖 - &gt; BindGrid()

也许这是我缺乏web开发经验,但这似乎是一个巨大的混乱,某些地方可能不需要做。

0 个答案:

没有答案