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

发布于 2024-11-18 16:30:03 字数 2841 浏览 4 评论 0原文

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

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

这是应用程序的屏幕截图:

在此处输入图像描述

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

感谢您的查看!

Background: I have an web form that autpostbacks a list of bundles to a listbox based on the carriers selected. When Postback happens, all user entered data is cleared.

How do I prevent the AutoPostback function from clearing entered data from the forms?

Here's a screenshot of the app:

enter image description here

asp front end code:

                    <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 code behind:

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

Thanks for looking!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪是无色的血 2024-11-25 16:30:03

您的控件是动态构建的吗?如果没有,只需启用视图状态即可。

Are you control built dynamically ? If not, simply enable the viewstate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文