2013-03-01 80 views
0

我的頁面上有一些跨度值具有值屬性。爲什麼InnerHtml,InnerText和屬性值在回發時爲空?

當我試圖從後面的代碼中獲取這些屬性時,我只獲取前兩個 - 其餘爲空,即使值屬性存在且不爲空。

請問?這是我的標記:

<div class="ExtraContainer"> 
    <div class="box_slider"> 
    <form id="Form1" runat="server"> 
     <div class="block block1"> 
      <h3> 
       Vælg områder</h3> 
      <div class="wraper"> 
       <input id="chkAllAreas" type="radio" name="group1" class="input_radio" runat="server"/> 
       <label for="chkAllAreas"> 
        Vis alle områder</label> 
      </div> 
      <div class="wraper"> 
       <input id="chkCustomAreas" type="radio" name="group1" class="input_radio" runat="server"/> 
       <label for="chkCustomAreas"> 
        Vælg områder</label> 
      </div> 
     </div> 
     <div class="block block2"> 
      <h3> 
       Vælg Ledighed</h3> 
      <div class="wraper"> 
       <input id="chkShowAll" type="radio" name="group2" class="input_radio" runat="server" /> 
       <label for="chkShowAll"> 
        Vis alle boliger</label> 
      </div> 
      <div class="wraper"> 
       <input id="chkIsAvailable" type="radio" name="group2" class="input_radio" runat="server" /> 
       <label for="chkIsAvailable"> 
        Vis kun ledige boliger</label> 
      </div> 
     </div> 
     <div class="block block3"> 
      <h3> 
       Vælg boligtype</h3> 
      <div class="wraper go_left"> 
       <input id="chkAllTHousingTypes" type="checkbox" class="input_check" runat="server" /> 
       <label for="chkAllTHousingTypes"> 
        Vis alle boligtyper</label> 
      </div> 
      <div class="wraper go_left"> 
       <input id="chkFamilieboliger" type="checkbox" class="input_check" runat="server" /> 
       <label for="chkFamilieboliger"> 
        Familieboliger</label> 
      </div> 
      <div class="wraper go_left"> 
       <input id="chkUngdomsboliger" type="checkbox" class="input_check" runat="server" /> 
       <label for="chkUngdomsboliger"> 
        Ungdoms- &amp; studieboliger</label> 
      </div> 
      <div class="wraper go_left"> 
       <input id="chkAeldrebolig" type="checkbox" class="input_check" runat="server" /> 
       <label for="chkAeldrebolig"> 
        Senior- &amp; ældreboliger</label> 
      </div> 
     </div> 
     <div class="clear"> 
      &nbsp;</div> 
     <div class="line"> 
      &nbsp;</div> 
     <div class="block4 go_left"> 
      <h3> 
       Vælg økonomi</h3> 
      <div class="slider_info"> 
       <div class="slider_info_leftright_container"> 
        <div class="slider_info_left"> 
         <span>Husleje</span> 
        </div> 
        <div class="slider_info_right" style="float: right"> 
         <span id="huslejefra" runat="server"></span> <em>til</em> <span id="huslejetil" runat="server"></span><span>kr</span> 
        </div> 
       </div> 
       <div class="Slider"> 
        <div id="husleje-slider-range"> 
        </div> 
       </div> 
      </div> 
      <div class="slider_info"> 
       <div class="slider_info_leftright_container"> 
        <div class="slider_info_left"> 
         <span>Indskud</span> 
        </div> 
        <div class="slider_info_right" style="float: right"> 
         <span id="indskudfra" runat="server"></span> <em>til</em> <span id="indskudtil" runat="server"></span><span>m2</span> 
        </div> 
        <div class="Slider"> 
         <div id="indskud-slider-range"> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    <div class="block4 go_right"> 
     <h3> 
      Vælg størrelse</h3> 
     <div class="slider_info"> 
      <div class="slider_info_leftright_container"> 
       <div class="slider_info_left"> 
        <span>Antal værelser</span> 
       </div> 
       <div class="slider_info_right" style="float: right"> 
        <span id="rumfra" runat="server">3</span> <em>til</em> <span id="rumtil" 
         runat="server">6</span><span>rum</span> 
       </div> 
      </div> 
      <div class="Slider"> 
       <div id="rum-slider-range"> 
       </div> 
      </div> 
     </div> 
     <div class="slider_info"> 
      <div class="slider_info_leftright_container"> 
       <div class="slider_info_left"> 
        <span>m2</span> 
       </div> 
       <div class="slider_info_right" style="float: right"> 
        <span id="storrelsefra" value="2" runat="server"></span> <em>til</em> <span id="storrelsetil" runat="server"></span><span>m2</span> 
       </div> 
      </div> 
      <div class="Slider"> 
       <div id="storrelse-slider-range"> 
       </div> 
      </div> 
     </div> 
    </div> 
    <asp:Button ID="searchButton" OnClick="ImgSearch_Click" Text="Søg" runat="server" /> 
    </form> 

    <div class="clear"> 
     &nbsp;</div>    


</div> 
    <div class="block5"> 
     <h3> 
      Vælg resultatvisning</h3> 
      <div class="buttonswrapper"> 
     <div class="wraper"> 
      <input id="id9" type="radio" class="input_radio" /> 
      <label for="id9"> 
       Billedevisning</label> 
     </div> 
     <div class="wraper"> 
      <input id="id10" type="radio" class="input_radio" /> 
      <label for="id10"> 
       Kortvisning</label> 
     </div> 
     </div> 
     <a class="link_img resetBtn" href="#"> 
      <img src="style/images/select_img.png" alt="" />Nulstil søgningen</a> 
    </div> 

    <div class="clear">&nbsp;</div> 

<input id="HDSelectedAreas" type="hidden" runat="server" class="HSelectedArea" /> 
</div> 

搜索按鈕看起來像這樣在ASPX:

<asp:Button ID="searchButton" OnClick="ImgSearch_Click" Text="Søg" runat="server" /> 

這是後面的代碼:

protected void ImgSearch_Click(object sender, EventArgs e) 
     { 

      String cRoomsFrom = rumfra.Attributes["value"]; 
      String cRoomsTo = rumtil.Attributes["value"]; 
      String cSizeFrom = storrelsefra.Attributes["value"]; 
      String cSizeTo = storrelsetil.Attributes["value"]; 
      String cRentFrom = huslejefra.Attributes["value"]; 
      String cRentTo = huslejetil.Attributes["value"]; 
      String cDepositFrom = indskudfra.Attributes["value"]; 
      String cDepositTo = indskudtil.Attributes["value"]; 
} 

初始化值:

<script type="text/javascript" language="javascript"> 

     function setupSlider(min, max, step, values, sliderElement, minelement, maxelement) { 

      $(sliderElement).slider({ 
       range: true, 
       min: min, 
       max: max, 
       values: values, 
       step: step, 
       slide: function (event, ui) { 
        $(minelement).html(ui.values[0]); 
        $(maxelement).html(ui.values[1]); 
        $(minelement).attr('value', ui.values[0]); 
        $(maxelement).attr('value', ui.values[1]); 
        __doPostBack(); 
       } 
      }); 

      $(minelement).html($(sliderElement).slider("values", 0)); 
      $(maxelement).html($(sliderElement).slider("values", 1)); 
      $(minelement).attr('value', $(sliderElement).slider("values", 0)); 
      $(maxelement).attr('value', $(sliderElement).slider("values", 1)); 
     } 

     function initializeSliders() 
     { 
      // størrelse slider 
      var values = [10, 80]; 
      setupSlider(10, 80, 10, values, "#storrelse-slider-range", "#storrelsefra", "#storrelsetil"); 

      // husleje slider 
      values = [1000, 7000]; 
      setupSlider(1000, 12000, 1000, values, "#husleje-slider-range", "#huslejefra", "#huslejetil"); 

      /// rum 
      values = [3, 6]; 
      setupSlider(1, 8, 1, values, "#rum-slider-range", "#rumfra", "#rumtil"); 


      // indskud 
      values = [3000, 7000]; 
      setupSlider(1000, 10000, 1000, values, "#indskud-slider-range", "#indskudfra", "#indskudtil"); 

      //fix color 
      fixToolTipColor(); 

     } 

     $(document).ready(function() { 
      $('.Udvidet').live('click', function() { 
       $('.UdvidetSoegning').toggle('slow'); 
      }); 
      $(function() { 
       initializeSliders(); 
       $(".resetBtn").live("click", function() { 
        initializeSliders(); 
        __doPostBack(); 
       }); 

      }); 
     }); 
    </script> 

我試過改變t InnerHtmlInnerText,但結果是一樣的。有時value屬性爲null,但是然後InnerHtml或InnerText返回實際值:S

回答

2

在回發後只會發佈input元素。

所以他們和之前的帖子回來一樣,他們在回帖前有什麼,現在和現在。所以其實你不「獲取」這個參數在代碼後面,你只「設置」他們和服務器控件與viewstate上,你可以記住這個參數在回發 - 但你不能改變他們在客戶端並期望在服務器上讀取此更改。

這裏的解決方法是。以太網使用頁面的視圖狀態來保存一些值並將它們保存在回發之後,以太使用輸入隱藏元素將它們回發。

+0

有沒有辦法解決這個與我目前的標記? – Kenci 2013-03-01 10:21:12

+0

@Kenci你想要存檔什麼?在客戶端更改此值或只記住它們? – Aristos 2013-03-01 10:22:47

+0

我需要在客戶端更改它們,並在後面的代碼中使用它們來根據值查詢我的數據庫 – Kenci 2013-03-01 10:24:02

相關問題