简体   繁体   中英

Integrating Javascript to aspx page

Good Day. I am trying to integrate this javascript code to my aspx page. I found the code below when I was looking for a tristate checkbox for asp.net webforms.

Code:

<input type="checkbox" id="cb1" onclick="ts(this)"  runat="server"/>

JS:

<script type="text/javascript">
        function ts(cb) {
            if (cb.readOnly)
                cb.checked = cb.readOnly = false;
            else if (!cb.checked)
                cb.readOnly = cb.indeterminate = true;
        }
    </script>

Basically what I want to happen is when checkbox was click it will execute a certain datasource specified for it and display it in the gridview.

Example:

DataSource1 : Select * from Students

DataSource2 : Select * from Students Where Gender = 'Male'

DataSource3 : Select * from Students Where Gender = 'Female'

Since the checkbox was customized. I want it to execute a certain datasource depending on what state it is , check/uncheck/null(indeterminate). My problem is , I am new to JS and no prior experience. I don't know how to execute the datasource through the JS code above or access it in code behind.

Suggestion:

Replace your aspx code

<input type="checkbox" id="cb1" onclick="ts(this)" runat="server"/>

With this

<input type="checkbox" id="cb1" onclientclick="ts(this); return false;" runat="server"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM