我的场景:
- 我在
UpdatePanel
. - 我想组合我的脚本,所以我使用
CompositeScript
inScriptManager
,并包括对WebUIValidation.js
- 我正在使用 .NET 4.0
我的问题:
- 当我异步更新面板时,.NET 在异步响应中加载
WebUIValidation.js
(在Scriptresource.axd
文件中),即使它已在初始CompositeScript
生成的脚本中加载。这是一个问题,因为我有自定义代码劫持了一些函数WebUIValidation.js
,并且异步响应覆盖了我的劫持。 - 如果将引用移至
WebUIValidation.js
inScripts
,ScriptManager
则没有问题。 - 如果您要拥有(我知道毫无意义)
WebUIValidation.js
中的唯一项目,CompositeScript
那么就没有问题。 - 这种异步重新加载不会发生在其他 .NET 库脚本中,例如
WebForm.js
我想知道的:
WebUIValidation.js
当异步响应已经包含在其中时,是否有理由将其加载到异步响应中CompositeScript
?
今天有人发布了一个类似(但不重复)的问题,并且正在转向说WebUIValidation.js
可能无法由ScriptManager
. 任何人都可以验证这一点吗?
要复制使用以下两个文件
test1.js
// To be added to the composite script
console.log('Test 1 Loaded');
测试.aspx
<%@ Page Language="vb" AutoEventWireup="false" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
<script language="VB" runat="server" runat="server">
Protected Sub ButtonClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles TestButton.Click
ButtonClickFeedback.Text = "Button clicked At " & Date.Now.ToString & "; Look at the scripts in your Developer Tools, there is now a separate script for WebUIValidation.js loaded, in spite of the composite script."
End Sub
</script>
<form runat="server">
<asp:ScriptManager runat="server">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="~/test.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
</Scripts>
</CompositeScript>
</asp:ScriptManager>
<h1>WebUIValidation.js, CompositeScript and UpdatePanel test</h1>
<asp:UpdatePanel runat="server" ID="ButtonUpdatePanel">
<ContentTemplate>
<asp:Label runat="server" >This is a section with a validator that is within an UpdatePanel. If you look at the scripts loaded, you will see the composite script in the detail.</asp:Label>
<asp:Textbox ID="TestInputForValidator" runat="server" Text="This is populated so it will validate"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="TestInputForValidator" ErrorMessage="You must write something" /><br />
<asp:Button ID="TestButton" Text="Click Me!" runat="server" /><br />
<asp:Literal ID="ButtonClickFeedback" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TestButton" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
如果您使用开发人员工具检查正在加载哪些脚本,您应该会在单击按钮后看到一个额外的 Scriptresource.axd(包含 WebUIValidation.js)被加载,尽管存在带有 Scriptresource.axd 的复合脚本。test.js 只是一个示例 js 文件,用于模拟复合脚本的想法。