My scenario:
- I have a validator in an
UpdatePanel
. - I want to combine my scripts so I am using
CompositeScript
inScriptManager
, and including a reference toWebUIValidation.js
- I am using .NET 4.0
My problem:
- When I asynchronously update the panel, .NET loads
WebUIValidation.js
(in aScriptresource.axd
file) in the async response, even though it has been loaded in the initialCompositeScript
-generated script. This is a problem because I have custom code that hijacks some functions inWebUIValidation.js
, and the async response overrides my hijacks. - If you move the reference to
WebUIValidation.js
toScripts
inScriptManager
, there is no problem. - If you were to have
WebUIValidation.js
as the only item inCompositeScript
(pointless I know) then there is no problem. - This async reload does not happen with other .NET library scripts, e.g.
WebForm.js
What I want to find out:
- is there a reason why
WebUIValidation.js
is loaded in the async response when it is already included in theCompositeScript
?
Someone has posted a similar (but not duplicate) issue today, and is veering towards saying that WebUIValidation.js
might not be handled by ScriptManager
. Can anyone verify this?
To replicate use the following two files
test1.js
// To be added to the composite script
console.log('Test 1 Loaded');
test.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>
If you use your Developer Tools to inspect what scripts are being loaded in, you should see an additional Scriptresource.axd (that contains WebUIValidation.js) getting loaded in after clicking the button, in spite of the existence of a Scriptresource.axd with the composite script. test.js is just a sample js file to simulate the idea of composite scripts.