admin管理员组文章数量:1384521
I tried to call the function ApplyCSS() which is in my SearchPage.ascx page inside the Script tag and in .CS file I am trying to call that function using the below code:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "ApplyCSS();", true);
but I am getting javascript runtime error object expected.
I tried to call the function ApplyCSS() which is in my SearchPage.ascx page inside the Script tag and in .CS file I am trying to call that function using the below code:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "ApplyCSS();", true);
but I am getting javascript runtime error object expected.
Share Improve this question edited May 8, 2014 at 12:02 Moha Dehghan 18.5k3 gold badges59 silver badges74 bronze badges asked May 8, 2014 at 12:02 user3395635user3395635 171 gold badge1 silver badge7 bronze badges 1- Closely look at the call-stack of the error to find out what causes the error. If you are using Google Chrome, press F12 and use the Developer Tools. – Moha Dehghan Commented May 8, 2014 at 12:12
3 Answers
Reset to default 2The likely cause of this error is that ApplyCSS();
isn't defined at the time when the function is called.
So, is the ApplyCSS();
function defined in a .js file? If so, you have to go with this kind of approach:
$(document).ready(function () { ApplyCSS(); } );
You'll need jQuery to do this
<script type="text/javascript">
function MyFunc(){
};
</script>
ScriptManager.RegisterStartupScript(this, Page.GetType(), "key", "MyFunc()", true);
Semicolon is not required after MyFunc() Call. You can refer this link
Have your script line is should be
<script type='text/javascript' language="javascript">
//ApplyCSS();
</script>
and please check your function is does not threw any error.
and try with this
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "javascript:ApplyCSS();", true);
本文标签: cHow to call javascript function in code behind cs file in AspnetStack Overflow
版权声明:本文标题:c# - How to call javascript function in code behind .cs file in Asp.net - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744484910a2608393.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论