Search code examples
asp.netvb.netdatalist

how to findcontrol inside datalist panel1 control?


I have a literal8 inside panel1 and panel1 inside datalist1 ..

i wanna insert the value in literal1 on page load event using query string ...

ERROR on Page Load : Object reference is not set to the instance of an object

how to make this code workin ?

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim lit8 As Literal = DirectCast(DataList1.FindControl("Literal8"), Literal)

        lit8.Text = Me.Request.QueryString("room")
    End Sub

Solution

  • Why don't you do a

    if(Panel1.FindControl("Literal8") is Literal)
       (Panel1.FindControl("Literal8") as Literal).Text ="your text";
    

    You should be setting this in Page_Load