简体   繁体   English

如何将javascript文件(.js文件)添加到ac#项目并从c#代码调用javascript方法

[英]How to add a javascript file (.js file) to a c# project and call a javascript method from c# code

I have added the javascript file to the project by right clicking the project.But while calling the method inside the code, I am getting an error stating 'The requested url(method) is unavailable'. 我已经通过右键单击项目将javascript文件添加到了项目中,但是在代码中调用该方法时,出现了一条错误消息,指出``请求的url(方法)不可用''。 So I don't know how to proceed further. 因此,我不知道如何进一步进行。 I need this for creating an IE browser add-on. 在创建IE浏览器加载项时,我需要此功能。 Please help me. 请帮我。

Added the javascript file. 添加了javascript文件。 In visual studio : drag and drop the js file to the aspx and it will make a tag like 在visual studio中:将js文件拖放到aspx中,它将像

 <script src="~/Scripts/jquery.min.js"></script>

Calling Javascript from codebehind 从代码隐藏中调用Javascript

in codebehind 在代码背后

 ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert('test');", true);
 ScriptManager.RegisterStartupScript(this, GetType(), "importingdone", "ImportingDone();", true);

calls this scripts in the front 在前面调用此脚本

 <script type="text/javascript">
        function Showalert(name) {
            alert('Profile not parsed!!' + name);
            window.parent.parent.parent.location.reload();
        }

        function ImportingDone() {
            alert('Importing done successfull.!');
            window.parent.parent.parent.location.reload();
        }
    </script>

Note : first call is with parameter, second without. 注意:第一次调用带有参数,第二个不带参数。

If you need otherwise read the article below. 如果您另有需要,请阅读以下文章。

http://www.codeproject.com/Tips/850541/JqueryAjaxToCs http://www.codeproject.com/Tips/850541/JqueryAjaxToCs

Hope it helps you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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