Reputation: 187
I want to set asp label to catch Cookie content,
I set
<p><asp:Label ID="lblUserID" runat="server" Text=""></asp:Label></p>
in USERINFO.aspx
then set
Public Class USERINFO
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If (Request.Cookies("userInfo")("vID") IsNot Nothing) Then
lblUserID.Text = Request.Cookies("userInfo")("vID").ToString
End If
End If
End Sub
End Class
in USERINFO.aspx.vb
But got visual studio alert :lblUserID not defined
What should I do to connect the label correctly ?
Upvotes: 0
Views: 371
Reputation: 187
Thanks to @Andrew Morton, I solve the problem. My issue is caused by that I didn't declare lblUserID in in USERINFO.aspx.designer.vb, I also didn't wrote the Inherits tag in USERINFO.aspx like
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="USERINFO.aspx.vb" **Inherits="MyProject.USERINFO"** %>
Correctly.
Upvotes: 1
Reputation: 476
I am not sure exactly, but you may still double-check if there's no typo in design and code-behind files.
Also, I noticed you're using ToString without parentheses, which is not correct. Please change it to -
lblUserID.Text = Request.Cookies("userInfo")("vID").ToString()
Upvotes: 2