Avatar of Guru Ji
Guru Ji
Flag for Canada

asked on 

Check only one checkbox in my usercontrol ASCX file

I have two checkboxes in Detailview templatefield in Sharepoint inside a Usercontrol. I just want only one checkbox to be selected at a time
this is what I am doing so far

in my Default.ascx page I have the following Javascript code
<script type='text/javascript'>
    var checkedObject = null;
    function isChecked(what) {
        if (checkedObject == null) {
            checkedObject = what;
            return true;
        else {
            if (what == checkedObject) {
                if (!what.checked) {
                    checkedObject = null;
                    return true;
            else {
                //alert('You can only choose one option');
                return false;
and in my Default.ascx.cs I have following lines in my Page_Load event

            CheckBox chkV = (CheckBox)dvNotes.FindControl("chkV");
            CheckBox chkS = (CheckBox)dvNotes.FindControl("chkS");

            chkV.Attributes.Add("onclick", "javascript:isChecked(this);");
            chkS.Attributes.Add("onclick", "javascript:isChecked(this);");

Its not working, is there any other way to accomplish this


.NET ProgrammingASP.NETMicrosoft SharePoint

Avatar of undefined
Last Comment
Roopesh Reddy

8/22/2022 - Mon