Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Check only one checkbox in my usercontrol ASCX file

Avatar of Guru Ji
Guru JiFlag for Canada asked on
.NET ProgrammingASP.NETMicrosoft SharePoint
6 Comments1 Solution611 ViewsLast Modified:
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;
            }
        }
    }
</script>
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

Thanks,

Moe
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers