views:

61

answers:

1

Ok, I've been trying to get this working for a few now and thought enough is enough and leave it to you guys to help. Depending on what I click, true or false, this will cause my table to show or hide accordingly. My issue is, if i cancel(close) out of this while the selected is "true", and come back to this, "true" will still be selected and vice versa for "false". What I want to achieve is, regardless of the selected value, when I close out of this and come back, the selected value should alway be set to "false". Any ideas?

<%
             var rblRecurrence = new SelectList(new List<ListItem> { 
                    new ListItem { Text = "Yes", Value="true" }, 
                    new ListItem { Text = "No", Value="false" }}, "Value", "Text", "false");

             var htmlAttributes = new Dictionary<string, object> { 
                { "onclick", "if(eval(this.value)) { $('#tblRecurrence').show('slow'); } else { $('#tblRecurrence').hide('slow'); }" } 
            }; 

             foreach (var rbl in rblRecurrence)
             {
                 %>
                    <%=Html.RadioButton("rblRecurrenceVal", rbl.Value, rbl.Selected, htmlAttributes)%> 
                    <label><%=rbl.Text%></label>   
                 <%
             }    
        %>
+1  A: 

I'm guessing that when you say you close out you are not closing the browser or page, but just a section within the page.

So I'm also guessing you have some sort of script somewhere else that opens this section back up. In there is where you will want to reset the values of your radio button.

To reset I would try something like this

$('input[name="rblRecurrenceVal"][value="false"]').attr('checked', true);  

If I'm wrong about how your page works, you should elaborate as to what the "this" means in "...if i cancel(close) out of this..."

Criss
sorry about that. what I mean by "cancel/close out of this" is closing out of a modal.
hersh
@ Criss -- I've tried your code and it is working for me. What I was missing is "[value="false"]. So by inserting that, I was able set the value to false regardless of the selected value before. Thanks!
hersh