JavaScript的asp.net中母版不加载 [英] javascript in asp.net masterpage doesn't load

查看:219
本文介绍了JavaScript的asp.net中母版不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JScript1.js我的豆蔻报警功能已经不结果工作
它没有工作,但我不能让它再工作!结果
我做了清洁和重建,重新启动计算机等结果
我的电脑的Windows 10,微软边缘,VS 2010结果
我怎样才能得到它再次合作?结果
如果一个副本code中,它正在一个新的项目,看到底部,在这种情况下,它持有错误的信息?
哦,我找到了解决方法!

My litte alert function in JScript1.js doesn't work anymore
It did work, but I can not get it to work again !!!
I did clean, and rebuild, reboot pc etc.
My pc Windows 10, Microsoft Edge, VS 2010
How Can I get it working again ?
If A copy the code in a new project it is working, see bottom, in which case it's holding wrong information? Oh I found a solution !

我的Site.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebJavascriptTest.SiteMaster" %>

<!DOCTYPE etc etc...">
<head runat="server">
 <script type="text/javascript" src="JScript1.js"></script>

我的About.aspx

-<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="About.aspx.cs" Inherits="WebJavascriptTest.About" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Javascript in file
    </h2>
    <asp:Button ID="B1" runat="server" Text="Button" OnClientClick="notify()" /

我的JScript1.js

function notify() {
    alert('notify test');
}

我的工作WebJava.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebJava.aspx.cs" Inherits="WebJavascriptTest.WebJava" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" language="javascript">
    function Func() {
        alert("hello!")
    }
</script>
    <h2>
        Java Intern
    </h2>
    <asp:Button ID="B1" runat="server" Text="Button" OnClientClick="Func()" />

使同一个测试项目
添加新的项目结果
ASP.NET Web应用程序的结果
添加新项JaScript文件名JScript1.js结果
把code在JScript1.js

To Make a same test project Add new project
ASP.NET Web application
Add new item JaScript file name JScript1.js
Put code in JScript1.js

function notify() {
    alert('notify test');
}

在添加下的Site.Master链接样式下一行:

Add in Site.Master under link-stylesheet next line:

   <script language="javascript"  type="text/javascript" src="JScript1.js"></script>

在About.aspx添加下一行约下:

Add next line in About.aspx under about:

  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="notify()" /><br />

现在你有一个工作的例子结果
但在某些时刻它不工作了,怎么可能呢?结果

Now you have a working example
But at some moment it doesn't work anymore, how is that possible?

解决方案:结果
VS负荷后,并显示该网页,点击重装,我在我的情况下,它的工作!?!

Solution:
After VS load and show the webpage, click on reload, I my case it's working !?!

推荐答案

问题是由该JScript1.js文件存储在浏览器高速缓存中的事实而引起的。你运行应用程序时,都会在文件的缓存版本是用来代替目前的版本。例如,如果你改变了code表示:

The problem is caused by the fact that the JScript1.js file is stored in the browser cache. Every time you run the application, the cached version of the file is used instead of the current version. For example, if you change the code for:

function notify() {
    alert('Notify 2');
}

和再次运行应用程序,你不会看到这个新的消息,除非你清除浏览器缓存(或如果浏览器被设置为自动清除它)。

and run your application again, you will not see this new message unless you clear your browser cache (or if the browser is set to clear it automatically).

您可以强制浏览器每个应用程序启动时附加一个不同的查询字符串的文件名来加载新的JavaScript文件:

You can force the browser to load the new Javascript file by appending a different query string to the file name each time the application starts:

<script type="text/javascript" src="JScript1.js?<%# DateTime.Now.Ticks.ToString() %>"></script>

在实际应用中,它是preferable强制浏览器下载JScript1.js只有当它的内容已被修改。这可以通过附加的文件版本的文件名(代替一个时间刻度计数)来完成。该脚本报关行看起来是这样的:

In real world applications, it is preferable to force the browser to download JScript1.js only when its content has been modified. This can be done by appending the file version to the file name (instead of a time tick count). The script declaration line could look like this:

<script type="text/javascript" src="JScript1.js?version=<%# AppVersion %>"></script>

这将使用定义的AppVersion属性code-背后:

which would use an AppVersion property defined in code-behind:

public string AppVersion
{
    get
    {
        return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }
}

大会文件的版本应该再被更新(在项目的属性),当变化JScript1.js而成。

The version of the assembly file should then be updated (in the properties of the project) when a change is made in JScript1.js.

这篇关于JavaScript的asp.net中母版不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆