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
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
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
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.