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.