状态未保留在复选框中
我的网络表单中有一个复选框。每当我勾选它..并单击后退按钮时,它都不会保留其状态..当我使用下一个按钮返回同一页面时。
注意:在控件中启用视图状态
页面加载事件中没有代码
代码如下:
Protected Sub chkBx_SR_wu_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkBx_SR_wu.SelectedIndexChanged
Dim i As Integer
i = 0
Try
For i = 0 To chkBx_SR_wu.Items.Count - 1
If chkBx_SR_wu.Items(i).Selected Then
Select Case chkBx_SR_wu.Items(i).Value
Case "SR_MR"
chkbx_SR.Checked = True
Case "Sk_MR"
chkbx_SkRoom.Checked = True
Case "SC_SS"
chkbx_admin.Checked = True
Case "CS_MR"
chkbx_salesFloor.Checked = True
Case "TEAM_LEADER"
rb_tl.Enabled = True
chkbx_tlAdmin.Enabled = True
chkbx_tlJewellery.Enabled = True
chkbx_tlSalesFloor.Enabled = True
chkbx_tlSkRoom.Enabled = True
rb_tl.Items(0).Enabled = True
rb_tl.Items(1).Enabled = True
rb_tl.Items(2).Enabled = True
rb_tl.Items(3).Enabled = True
ReqiredFieldValidator1.Enabled = True
End Select
Else
Select Case chkBx_SR_wu.Items(i).Value
Case "SR_MR"
chkbx_SR.Enabled = False
chkbx_SR.Checked = False
Case "Sk_MR"
chkbx_SkRoom.Enabled = False
chkbx_SkRoom.Checked = False
Case "SC_SS"
chkbx_admin.Enabled = False
chkbx_admin.Checked = False
Case "CS_MR"
chkbx_salesFloor.Enabled = False
chkbx_salesFloor.Checked = False
Case "TEAM_LEADER"
chkbx_tlAdmin.Enabled = False
chkbx_tlAdmin.Checked = False
chkbx_tlJewellery.Enabled = False
chkbx_tlJewellery.Checked = False
chkbx_tlSalesFloor.Enabled = False
chkbx_tlSalesFloor.Checked = False
chkbx_tlSkRoom.Enabled = False
chkbx_tlSkRoom.Checked = False
rb_tl.Items(0).Enabled = False
rb_tl.Items(1).Enabled = False
rb_tl.Items(2).Enabled = False
rb_tl.Items(3).Enabled = False
ReqiredFieldValidator1.Enabled = False
End Select
End If
Next
Catch ex As Exception
End Try
End Sub"
There is a check box in my webform. whenever i tick it ..and click on back button it will not retain its state ..when i comeback using the next button to the same page.
Note: view state is enabled in the control
There is no code in the page load event
Code below:
Protected Sub chkBx_SR_wu_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkBx_SR_wu.SelectedIndexChanged
Dim i As Integer
i = 0
Try
For i = 0 To chkBx_SR_wu.Items.Count - 1
If chkBx_SR_wu.Items(i).Selected Then
Select Case chkBx_SR_wu.Items(i).Value
Case "SR_MR"
chkbx_SR.Checked = True
Case "Sk_MR"
chkbx_SkRoom.Checked = True
Case "SC_SS"
chkbx_admin.Checked = True
Case "CS_MR"
chkbx_salesFloor.Checked = True
Case "TEAM_LEADER"
rb_tl.Enabled = True
chkbx_tlAdmin.Enabled = True
chkbx_tlJewellery.Enabled = True
chkbx_tlSalesFloor.Enabled = True
chkbx_tlSkRoom.Enabled = True
rb_tl.Items(0).Enabled = True
rb_tl.Items(1).Enabled = True
rb_tl.Items(2).Enabled = True
rb_tl.Items(3).Enabled = True
ReqiredFieldValidator1.Enabled = True
End Select
Else
Select Case chkBx_SR_wu.Items(i).Value
Case "SR_MR"
chkbx_SR.Enabled = False
chkbx_SR.Checked = False
Case "Sk_MR"
chkbx_SkRoom.Enabled = False
chkbx_SkRoom.Checked = False
Case "SC_SS"
chkbx_admin.Enabled = False
chkbx_admin.Checked = False
Case "CS_MR"
chkbx_salesFloor.Enabled = False
chkbx_salesFloor.Checked = False
Case "TEAM_LEADER"
chkbx_tlAdmin.Enabled = False
chkbx_tlAdmin.Checked = False
chkbx_tlJewellery.Enabled = False
chkbx_tlJewellery.Checked = False
chkbx_tlSalesFloor.Enabled = False
chkbx_tlSalesFloor.Checked = False
chkbx_tlSkRoom.Enabled = False
chkbx_tlSkRoom.Checked = False
rb_tl.Items(0).Enabled = False
rb_tl.Items(1).Enabled = False
rb_tl.Items(2).Enabled = False
rb_tl.Items(3).Enabled = False
ReqiredFieldValidator1.Enabled = False
End Select
End If
Next
Catch ex As Exception
End Try
End Sub"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
复选框不使用 ViewState 来保留其状态 - 它们使用 HTTP POST 负载的内容来确定是否将控件设置为
Checked
。如果您需要在正常回发周期之外保留该值,则需要将其存储在会话中或类似的位置,以便在该时间范围之外继续存在。
Checkboxes don't use ViewState to retain their state - they use the contents of the HTTP POST payload to determine whether or not to set the control as
Checked
.If you need to persist this value beyond the normal postback cycle you will need to store it in session or somewhere similar that will survive beyond that timeframe.