简体   繁体   中英

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'. So I don't know how to proceed further. I need this for creating an IE browser add-on. Please help me.

Added the javascript file. In visual studio : drag and drop the js file to the aspx and it will make a tag like

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

Calling Javascript from codebehind

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

Hope it helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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