0

Good day

I have a VB.Net project. My main page is Display.aspx I have various usercontrols (ascx) that use this page. On one of these controls, I have a Literal, lblCatQuestion. In the code behind of the control

 Protected WithEvents lblCatQuestion As Literal

What this literal basically does is it loads up with some text and radio buttons. When clicking on the radio buttons, a Jquery form pops up. Upon completing the form and saving and closing, this literal should now display a message. The message comes from the main Display page's code behind

For purposes here, on the 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")

Problem is, when I debug, I always get a nullreferenceexception when trying to assign the text to the literal. When I look, the page here is described as

display_aspx enter image description here

but on my url, the page is

Display.aspx?pid=4

Could this be cauing the nullreferenceexception? As the page is not exactly Display.aspx anymore, but Display.aspx?pid=4 enter image description here

How would I change the literal's text now? How would I get the exact page, so that I can change the text value?

Thanks for the help

EDIT

This is declared in the control's code behind

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

But the text does not change. Hence why I'm looking into a different method

Nicholas Aysen
  • 568
  • 3
  • 18
  • 40

1 Answers1

0

If the Literal is within a user control, you have to look there, not within the page.

Session("CatMessage") = "Completed"
Dim label As System.Web.UI.WebControls.Literal
label = DirectCast(UserControl.FindControl("lblCatQuestion"), System.Web.UI.WebControls.Literal).Text = Session("CatMessage")
Rocoso
  • 193
  • 1
  • 10
  • i tried this. still didnt work. what i did have before was If Not Session("CatMessage") Is Nothing Then lblCatQuestion.Text = Session("CatMessage") End If but that didnt refresh the label. thats why i'm trying another way – Nicholas Aysen May 19 '16 at 09:02