Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a script I need to run under certain conditions to remove some elements in a gridview, and I haven't found any way to remove them other than with Javascript. While it's a better practice to reference a script in an external file, for now I'm merely trying to run the JS. Even getting an alert to work would be great, but nothing seems to do it. Is the issue that you're not supposed to do this from within an ascx file? Because I have no other option.

I've placed my script in various places and tried adding an onload property to the div within which everything else takes place, but no luck.

The div tag:

<div id="pSection" onload="fixButtons()">


The JS:

<script type="text/javascript">
    function fixButtons() {

        var tbl = document.getElementById("gvStudents");

        for (var i = 1; i < tbl.children.length; i++) {
            if (i != tbl.EditIndex) {
                tbl.rows[i].deleteCell[5];
                tbl.rows[i].deleteCell[6];
            }

        }

        alert("We did something!");
    }
    
</script>


Are you supposed to place your JS somewhere in particular? What am I missing?

Edit:

JS method deleteCell() was being called wrong in this script.

There were also problems with the script's registration; a typo there was preventing the script from being run.

What I have tried:

Registering the script with a ClientScriptManager object in the C# file.

Calling the function onload, onscroll, onclick, and every other method under the sun.
Posted
Updated 20-Jun-18 3:09am
v3
Comments
Bryian Tan 19-Jun-18 16:33pm    
Possible error in the function? Try remove everything, leave the alert and see if it works.
OlivesForDinner 20-Jun-18 9:04am    
Thanks for the tip. I was actually using deleteCell() wrong.
F-ES Sitecore 20-Jun-18 4:33am    
The order things appear on the page matters, so it might be that. We can't tell from the context you've provided.
OlivesForDinner 20-Jun-18 9:05am    
I've mostly figured this out. There was a problem with the registration of the script, as well as some issues with the script itself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900