• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1066
  • Last Modified:

Show/Hide Div tags from apsx.vb code

Hi Experts,

I'm writing a web application in asp.net using visual basic and I have the following div tag defined.  I also have another div tag in the same position overlaying this one, so at certain points I want to make this div tag hidden.  I need to do this from the aspx.vb file associated with this page.  I've declared the div tag as runat="server" as follows:

            <div id="runtestschoices" runat="server">
                <asp:CheckBoxList ID="CheckBoxList1" runat="server" CellPadding="0"
                    CellSpacing="0" Font-Size="Small">
                    <asp:ListItem Selected="True">Summary</asp:ListItem>
                    <asp:ListItem Selected="True">Extract fields</asp:ListItem>

This is the code I'm using in my aspx.vb file

        Dim runtestschoices As HtmlGenericControl
        runtestschoices.Visible = False

But at the 2nd line I get the following error 'Object reference not set to an instance of an object.'

Can someone tell me exactly how to hide/show div tags on my aspx page from the code behind the page?
1 Solution
Carl TawnSystems and Integration DeveloperCommented:
You shouldn't need the first line. Your DIV is already declared in the page and a HtmlGenericControl will already exist for it, so all you need to do is set the Visible property:
runtestschoices.Visible = False

Open in new window


Please find the attached project. I have done a similar one.

I think you should remove the below line:
Dim runtestschoices As HtmlGenericControl

MOSSPOINTAuthor Commented:
Thanks, sometimes the simplest things?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now