更改用户控件上的文字文本 VB.Net

Change Literal text on usercontrol VB.Net

美好的一天

我有一个 VB.Net 项目。 我的主页是 Display.aspx 我有各种使用此页面的用户控件 (ascx)。 在其中一个控件上,我有一个文字 lblCatQuestion。 在控件后面的代码中

 Protected WithEvents lblCatQuestion As Literal

这个文字的主要作用是加载一些文本和单选按钮。单击单选按钮时,会弹出一个 Jquery 表单。完成表单并保存并关闭后,此文字现在应显示一条消息。 该消息来自主显示页面的代码隐藏

出于此处的目的,在 Display.aspx.vb

 Session("CatMessage") = "Completed"
    Dim label As System.Web.UI.WebControls.Literal = New System.Web.UI.WebControls.Literal
    label = DirectCast(Page.FindControl("lblCatQuestion"), System.Web.UI.WebControls.Literal).Text = Session("CatMessage")

问题是,当我调试时,我总是在尝试将文本分配给文字时遇到 nullreferenceexception。 当我查看时,此处的页面被描述为

display_aspx

但在我的 url 上,页面是

Display.aspx?pid=4

这会导致 nullreferenceexception 吗?由于该页面不再完全是 Display.aspx,而是 Display.aspx?pid=4

我现在如何更改文字的文本? 我如何获得准确的页面,以便我可以更改文本值?

感谢您的帮助

编辑

这是在控件后面的代码中声明的

 If Not Session("CatMessage") Is Nothing Then
            lblCatQuestion.Text = Session("CatMessage")
        End If

但文字没有变化。因此,为什么我正在研究一种不同的方法

如果字面量在用户控件内,您必须在此处查看,而不是在页面内。

Session("CatMessage") = "Completed"
Dim label As System.Web.UI.WebControls.Literal
label = DirectCast(UserControl.FindControl("lblCatQuestion"), System.Web.UI.WebControls.Literal).Text = Session("CatMessage")