Calling a Javascript function from C# class
For some reason I can't figure out what I'm doing wrong on this - despite several things I've found on the internet.
I'm trying to adjust the size of the page based on information selected prior to the page load or upon a selected change in a dropdown. I have the controls in cells and rows in a table.
This is part of the aspx code:
<script language="Javascript">
function rowTestHide()
{ rowTest.style.display="none"; }
function rowTestShow()
{ rowTest.style.display="block"; }
</script>
Then in the .cs file, I've tried:
1. adding this - protected System.Web.UI.WebControls.Literal useJS;
then in the Page_Load and SelectedIndexChange methods, I've put:
.....
useJS.Text="<script language='javascript'>rowTestHide()</script>";
--this errors when hit
2. Just adding in the Page_Load and SelectedIndexChange methods:
Javascript:rowTestHide();
--this errors when hit
3. Or I tried this:
String scriptString = "<script language=JavaScript> " ;
scriptString += "function rowTestHide(){";
scriptString += "rowTestHide.style.display='none';}";
scriptString += "</script>";
Response.Write(scriptString);
--this also errors when I try it
As you can probably see, I don't know what I'm doing. This seems that it would be siimple enough, but I haven't figured it out.
Thanks for your help.