views:

1045

answers:

2

asp:RadioButton GroupName="EndorsementType" runat="server" ID="rdoRemoveProperty" Text="Remove Property from TIV" />

I was thinking about implementing a custom validator, and using a client javascript function to reference the radio button ids, (I'm using web forms, not mvc),

something like.. if(document.getElementById(<%= rdoAddProperty.ClientId %>).checked == true) && ...

Anyone know of a way to do it without knowing the clientId?

A: 

You will have to put your client id out to the form, as with INamingContainer your ID can change in relation to the other information that is stored on the server.

Mitchel Sellers
i forgot to mention the radio button is also nested inside a wizard's template step, so you think I should just expose it's client id as a property in the code behind/ server side code?
Nathan Prather
+2  A: 

If your radios are contained within something like a DIV, and because your asp:RadioButtons will render as HTML inputs, you could do something like:

<script type="text/javascript" language="javascript">
    function Validate()
    {
        var l_elemsRadios = document.getElementById("MyRadios").getElementsByTagName("input");

        if (l_elemsRadios == null)
            return;

        for (var i = 0; i < l_elemsRadios; i++)
        {
            // validate l_elemsRadios[i] through l_elemsRadios[n]
        }
    }
</script>


<div id="MyRadios">
    <input type="radio" name="EndorsementType" value="Remove Property from TIV" >Remove Property from TIV
    .
    .
    .
</div>
Bullines
that should be .getElementsByTagName() <-- *Tag* .getElementsByName() would be used if you wanted all elements with the name attribute "EndorsementType"
scunliffe
Ooops. Forgot the "Tag" - I've edited it back in. Thanks for catching that :)
Bullines