我的vb.net應用程序需要使用會話變量。我真的不知道如何在ASP.net中使用它。我一直在嘗試使用我的書,但是我無法獲得這個標籤。我需要根據數據庫對用戶輸入進行驗證,如果他們的代碼位於數據庫中,那麼文本框應該消失,並且會出現一個標籤,表示歡迎。使用會話變量的VB.net標籤
我寫它的方式,我得到一個錯誤,說服務器標籤不正確形成,並在代碼隱藏它說,我的標籤的ID沒有聲明。任何人都可以發現我寫的代碼有問題嗎?
<asp:Label ID="lblIB" runat="server" DataSourceID="dsIBs"
Text="Welcome, <%# Eval("First_Name") %> '&' <%# Eval("Last_Name")%>">
</asp:Label>
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal
args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
args.IsValid = True
For Each drv As DataRowView In dsIBs.[Select](DataSourceSelectArguments.Empty)
If drv("baccount").ToString() = args.Value Then
args.IsValid = False
lblIB.Visible = False
Exit For
End If
Next
If args.IsValid Then
IBTextBox.Visible = False
IBTextBoxButton.Visible = False
lblIB.Visible = True
End If
End Sub
UPDATE:
<asp:Label ID="lblIB" runat="server" Text=""></asp:Label>
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
args.IsValid = True
For Each drv As DataRowView In dsIBs.[Select](DataSourceSelectArguments.Empty)
If drv("baccount").ToString() = args.Value Then
args.IsValid = False
lblIB.Visible = False
Exit For
End If
Next
If args.IsValid Then
IBTextBox.Visible = False
IBTextBoxButton.Visible = False
lblIB.Visible = True
lblIB.Text = String.Format("Welcome, {0} {1}", Session("FirstName"), Session("LastName"))
End If
End Sub
更新2:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
lblIB.Visible = False
End Sub
If args.IsValid Then
IBTextBox.Visible = False
IBTextBoxButton.Visible = False
lblIB.Visible = True
lblIB.Text = String.Format("Welcome, {0} {1}", Session("FirstName"),
Session("LastName"))
Protected Sub IBTextBoxButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles IBTextBoxButton.Click
Session("IB") = IBTextBox.Text
Dim IB As String = Session("IB")
Response.Redirect(Request.RawUrl + "&IB=" + Session("IB"))
End Sub
是數據綁定控件內的標籤? –
不,標籤只是坐在文本框和用戶用來輸入代碼的按鈕之後。在那裏有一個自定義的驗證器來驗證用戶對數據庫中代碼的輸入,但這也不起作用。 – jlg