Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<div style="margin-top:2%; width: 100%; background: #FFBF02;">
      <div id="blocks" runat ="server"  >
          <span id="snbox1" onclick="return ShowClick('Company');" class="span-box1"style="position: relative; cursor: pointer;">
                 <span id="snplaceholderFirma"  class="image-placeholderCompany"> <img id="img1" src="Images/images.png" style="height: 90px;" /> </span>
                 <span id="snFirma" style="background-color: #808080" class="text-content">Firma</span>
                 <span style="clear: both;"></span>
             </span>

            <span id="snbox2" onclick="" class="span-box2" style="position: relative; cursor: pointer;">
                <span id="snplaceholderBenutzer" class="image-placeholderUser"> <img id="img2" src="Images/images.png" style="height: 90px" /> </span>
                 <span id="snBenutzer" style="background-color: #808080" class="text-content"></span>
                 <span style="clear: both;"></span>
            </span>

            <span id="snbox3" onclick="" class="span-box3" style="position: relative; cursor: pointer;">
                <span id="snplaceholderFirmaMitarbeiter" class="image-placeholderCompanyEmployee"> <img id="img3" src="Images/images.png" style="height: 90px" /> </span>
                <span id="snFirmaMitarbeiter" style="background-color: #808080" class="text-content"> </span>
                <span style="clear: both;"></span>
            </span>
      </div>
    <div id="blocksTile"  runat ="server">
             <span id="snboxs1" onclick="" class="span-box1"style="position: relative; cursor: pointer;">
                 <span id="snplaceholderFirmas"  class="image-placeholderCompany"> <img id="imgs1" src="Images/images.png" style="height: 90px;" /> </span>
                 <span id="snFirmas" style="background-color: #808080" class="text-content">Test 1</span>
                 <span style="clear: both;"></span>
             </span>

            <span id="snboxs2" onclick="" class="span-box2" style="position: relative; cursor: pointer;">
                <span id="snplaceholderBenutzers" class="image-placeholderUser"> <img id="imgs2" src="Images/images.png" style="height: 90px" /> </span>
                 <span id="snBenutzers" style="background-color: #808080" class="text-content">Test 2</span>
                 <span style="clear: both;"></span>
            </span>

            <span id="snboxs3" onclick="" class="span-box3" style="position: relative; cursor: pointer;">
                <span id="snplaceholderFirmaMitarbeiters" class="image-placeholderCompanyEmployee"> <img id="imgs3" src="Images/images.png" style="height: 90px" /> </span>
                <span id="snFirmaMitarbeiters" style="background-color: #808080" class="text-content">Test 3</span>
                <span style="clear: both;"></span>
            </span>
      </div>

  </div>



This is the HTML Code. Based on a condition I want to hide/show the div.

C#
if (Convert.ToInt32(GlobalValues[0]) == 1)
                {
                   blocks.Visible = true;
                   blocksTile.Visible = false ;

                }
                else if (Convert.ToInt32(GlobalValues[0]) == 2)
                {
                    blocksTile.Visible = true;
                    blocks.Visible = false;
                }
                else
                {
                    blocks.Visible = true;
                    blocksTile.Visible = false;
                }

But it results NULL EXCEPTION ERROR... Please help me to solve this
Posted
Comments
m-shraddha 13-Jan-15 2:50am    
You might be getting value of GlobalValues[0] as a null...Therefore its throwing an exception because it cannot convert null value to an integer. You can check the value by debugging your code. :)
jithesh a 13-Jan-15 2:55am    
Ho..Never ...Its getting an integer value. Error is getting on div ;)
Sanket Saxena 13-Jan-15 7:42am    
On which event you are writing your code behind code?

debugging your code. And use HtmlGenericControl for HTML Control .
for ex.
HtmlGenericControl div = (HtmlGenericControl)this.FindControl("div1");
 
Share this answer
 
I found that you have this div inside another div that is not runat="Server". So make the parent also runat="server" and try.

ASP.NET
<div runat="server" style="margin-top:2%; width: 100%; background: #FFBF02;">
      <div id="blocks" runat="server"></div>
</div>


Hope it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900