开发者

Calling JavaScript Functions

开发者 https://www.devze.com 2023-01-17 17:39 出处:网络
I am trying to call some javascript functions which I ahve written in some file. Eg. function OpenPopup() {

I am trying to call some javascript functions which I ahve written in some file. Eg.

function OpenPopup() {

    alert("OpenPopUp");
        return false;

}

when I call this from button from OnClientClick = "OpenPopup()" it is not called but when I put this function on MasterPage it is able to call the function.

I added this is the MasterPages'开发者_StackOverflows Head

 <script src="Scripts/something.js" type="text/javascript"></script> 

Please let me know what can be the possiblities why it is not called.


There should be a ContentPlaceHolder in the pasterpage, in the head section with an id 'head'. You should place a Content tag in the slave page referring to that 'head' section place holder and place this script reference inside that. This way, the < script > tag is placed inside the < head > tag.


You might have given wrong scr for script file.just drag the file path in your master page.Doing so you will get the accurate path for file.


From what I gather from your question, your function call now works with the <script> tag in place, and you are unsure why the tag is necessary.

If you write your javascript function in a file, say "script.js" and then attempt to call the function in an ASP.NET page, the ASP.NET is not aware that script.js exists.

The <script> tag is letting your ASP.NET page know to include the file script.js so that any functions and variables defined in that file can be used. By putting the <script> tag in your MasterPage, you are including it in every page on your site. A better idea might be to include the <script> tag only on the pages in which you intend to use the javascript functions.


I tried using this and it worked

I don't know why but I checked with putting the absolute path instead of relative path and it worked. Thing is I chnaged it to While refrencing to the CSS is working fine with that relative path. I have no clue why it is happening

0

精彩评论

暂无评论...
验证码 换一张
取 消