我只想控制用户点击的按钮,因此我使用会话变量存储该数据,因为我必须在Page_Load
中创建所有动态控件(以允许事件处理程序正常工作)。问题是这个会话变量在我第一次点击时不起作用,但只是第二次。
这是我的代码:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'For the first time I want this session variable to be false because Image Button is not yet click
Me.Session("ImageClick") = False
End If
If Me.Session("ImageClick") Then
'Then after Button Image is clicked I try to add Dynamic control to a div
AddPreviewTable(0)
CreateButtomButton(Me.Session("totalPage"))
Debug.WriteLine(Me.Session("totalPage"))
Me.Session("ImageClick") = False
End If
End sub
问题是我必须点击ButtonImage
两次才能将Me.Session("ImageClick")
变为True。
答案 0 :(得分:0)
您的if
阻止不正确。您需要将会话对象转换为bool
:
If (Session("ImageClick") Is Not Nothing And CBool(Me.Session("ImageClick"))) Then
'Do your stuff.
End If