2011-02-01 58 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