显示/隐藏DIV时出现NullReferenceException

时间:2015-01-13 08:00:04

标签: html asp.net

在页面加载时显示/隐藏DIV时出现NullReferenceException错误。 block.visible = false的错误。请找到下面的代码

<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>

 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;
            }

但结果是NULL EXCEPTION ERROR ......................................... ..请帮我解决这个问题。

0 个答案:

没有答案