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
Roopesh Reddy
IT Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2012

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros