0

I have a simple asp:RadioButtonList within a form tag but for some reason it isn't keeping it's value on postback

Here's what I've got

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

At the moment all I'm trying to do is get it to keep it's value on postback - it works in Safari but not in Firefox or Internet Explorer.

Any ideas?

Edit:

I've just found out that it is something to do with my javascript in the head of my page

$(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' });      
    });
});
1
  • Have a look at the update of my answer. You should exclude input type=radio from this jQuery-function. Commented Feb 1, 2011 at 11:03

3 Answers 3

1

I'm guessing you have some other input elements on your page which use this javascript.

Try specifying the type of input you want the javascript to run on:

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

replace :text with the type you're using.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Tom just what I was after
0

I have pasted your code in a newly created ASP.NET website and was able to retrieve the SelectedValue and SelectedIndex properties.
Are you using a custom adapter for rendering HTML? Please take a look at: ASP.Net RadioButton loses ViewState

Comments

0

Is ViewState enabled for page and control?

  • EnableViewState property for the page is set to true.
  • EnableViewState property for the control is set to true.
  • ViewStateMode property for the control is set to Enabled or inherits the Enabled setting.

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

EDIT: you don't need to save the old "text" on a RadioButton (html=input type=radio), so you have to apply this function only on textboxes etc. I'm not so familiar with jQuery, but you should be able to do this with a jQuery selector. Maybe with the :not-selector/function:

[untested]

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.