VB.NET - 如何防止 AutoPostback 清除表单中输入的数据
背景:我有一个网络表单,可以根据所选的运营商将捆绑包列表自动回发到列表框。当回发发生时,所有用户输入的数据都将被清除。
如何防止 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的控件是动态构建的吗?如果没有,只需启用视图状态即可。
Are you control built dynamically ? If not, simply enable the viewstate.