VB.NET - 如何防止AutoPostback清除表单中输入的数据

时间:2011-07-06 20:05:14

标签: vb.net webforms autopostback

背景:我有一个网络表单,根据所选的运营商自动将一个包列表自动返回到一个列表框。发生回发时,将清除所有用户输入的数据。

如何阻止AutoPostback功能清除表单中输入的数据?

以下是应用的截图:

enter image description here

asp前端代码:

                                                                              

                    <asp:RequiredFieldValidator ID="CarrierValidator" runat="server" Text="*"
                        ErrorMessage="Select At Least 1 Carrier"  ControlToValidate="lbCarriers"
                        ValidationGroup = "ValidationGroup" ForeColor="Red" ></asp:RequiredFieldValidator>

        </td>
    </tr>
            <tr>
        <td class="style1">
            Bundles:<br />
            <font size="1">*Hold Ctrl Key Down to Select Multiple Bundles</font></td>
        <td bgcolor="#ffffff" class="style6">
            <asp:ListBox ID="bundles" SelectionMode="Multiple" runat="server" Height="86px" 
                Width="250px" Enabled="True" 
                ValidationGroup="ValidationGroup">
            </asp:ListBox>

vb.net代码背后:

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

        If Not IsPostBack Then

            'testing lines

            If MCshort = "" Then
                arryCarriers = proxy.GetCarrierNames(My.Settings.UserID, My.Settings.Password)
                arryMccompanies = proxy.GetMarketingCompanyNames(My.Settings.UserID, My.Settings.Password)
                GetMarketingCompanies()
                GetCarriers()

                'For Each item In arryCarriers
                '    If item.CarrierNameShort = "MOO" Or item.CarrierNameShort = "GBR" Then
                '        lbCarriers.Items.Add(String.Format("{0} | {1} | {2}", item.CarrierID, item.CarrierNameLong, item.CarrierNameShort))
                '    End If
                'Next

                For Each item In arryMccompanies
                    If item.MarketingCompanyShort = MCshort Then
                        MCNameLong = item.MarketingCompanyName.ToString

                    End If
                Next
            End If

            Dim splt() As String = User.Identity.Name.ToString.Split("\")
            MCshort = splt(0)
            ' mcShort = "AMG"
            txtMarketerName.Text = splt(1)

        Else

            Dim splt() As String = User.Identity.Name.ToString.Split("\")
            MCshort = splt(0)
            ' mcShort = "AMG"
            txtMarketerName.Text = splt(1)
            GetBundles()

        End If
    Catch ex As Exception
        WriteToEventLog(ex.Message, "Page_Load-Method", EventLogEntryType.Error, "aComp-utility")
    End Try

End Sub

感谢您的期待!

1 个答案:

答案 0 :(得分:0)

你是动态建造的吗?如果没有,只需启用视图状态。