2011-02-01 74 views
0

我有一個form標籤內的簡單asp:RadioButtonList但由於某種原因它不保持它在回傳值ASP.NET複選框由於JavaScript/jQuery數組而在回發中丟失值?

這裏就是我有

<form runat="server"> 
<div class="Form"> 
<span class="FirstField">   
    <asp:RadioButtonList runat="server" ID="radiolist1" AutoPostBack="true" RepeatDirection="Horizontal"> 
      <asp:ListItem Text="Yes" /> 
      <asp:ListItem Text="No" /> 
    </asp:RadioButtonList>   
</span> 
</div> 
</form> 

此刻所有我想要做是讓它在回發時保持它的價值 - 它在Safari中工作,但不在Firefox或Internet Explorer中。

任何想法?

編輯

我剛剛發現它是事做我的javascript在我的網頁

$(document).ready(function() { 
    var originalValues = new Array(); 
    $("input").focus(function() {  
     if (!originalValues[this.id]) { 
      originalValues[this.id] = $(this).val() 
     }   
     if ($(this).val()==originalValues[this.id]) { 
       $(this).val('').css({'color': "#000", 'font-style': 'normal'}); 
     } 

     $(this).css({'background-color':'#E8E8E8' });  
     }); 

    $("input").blur(function() { 
     if ($(this).attr("value")=="") { 
      $(this).val(originalValues[this.id]).css({'color': "#666", 'font-style': 'normal', 'font-weight': 'normal'}); 
     } 

     $(this).css({'background-color':'#fff' });  
    }); 
}); 
+0

看看我的答案的更新。你應該從這個jQuery函數中排除`input type = radio`。 – 2011-02-01 11:03:45

回答

1

我猜你在你的頁面上有一些其他的輸入元素使用這個javascript。

嘗試指定輸入的類型,你想要的JavaScript運行在:

$("input:text").focus(function() { 

替代:你正在使用的類型的文本。

+0

謝謝湯姆,我以後就是這樣 – 2011-02-01 11:19:23

0

的頭是頁面和控件啓用ViewState的?

  • 該頁面的EnableViewState屬性設置爲true。
  • 控件的EnableViewState屬性設置爲true。
  • 該控件的ViewStateMode屬性設置爲Enabled或繼承Enabled設置。

http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableviewstate.aspx

編輯:你並不需要保存在一個單選按鈕舊的「文本」(HTML = input type=radio),所以你只在文本框等我」應用此功能m不是 熟悉jQuery,但你應該可以用jQuery selector來做到這一點。也許與:not-selector /功能:

[未經測試]

$("input").not(input[type=radio]).focus(function() { 
0

我已經粘貼你的代碼在一個新創建ASP.NET網站,並能檢索SelectedValueSelectedIndex性能。
您是否使用自定義適配器來呈現HTML?請看看:ASP.Net RadioButton loses ViewState