Hi Imar,
In Chapter 11 you cover unobtrusive JavaScript validation. I followed your instructions and as usual everything worked as advertised. In the book you do not use Content Delivery Network as the source for the jQuery library, but I thought Iâd try to implement it in my Web Application project. I did a lot of reading on the web and added the CDN source without any trouble. Here are the modifications I made:
Global.asax
Code:
void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
ScriptResourceDefinition jQuery = new ScriptResourceDefinition();
jQuery.Path = "~/Scripts/jquery-2.2.2.min.js.";
jQuery.DebugPath = "~/Scripts/jquery-2.2.2.js";
jQuery.CdnPath = "http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.2.min.js";
jQuery.CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.2.js";
jQuery.CdnSupportsSecureConnection = true;
jQuery.LoadSuccessExpression = "window.jQuery";
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", jQuery);
}
Web.config
Code:
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms"/>
</appSettings>
ScriptManager
Code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true" >
<Scripts>
<asp:ScriptReference Name="jquery" />
</Scripts>
</asp:ScriptManager>
Page Source partial view:
Code:
<script src="http://ajax.aspnetcdn.com/ajax/4.6/1/WebForms.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
window.WebForm_PostBackOptions||document.write('<script type="text/javascript" src="/WebResource.axd?d=pynGkmcFUV13He1Qd6_TZDK1rSI7GaESqe2XElTAO7CWQBVn5WVBZ4MtmH-WpeftFSc7dc4wnmXs-4SpZqpJCQ2&t=635823490080000000"><\/script>');//]]>
</script>
<script src="http://ajax.aspnetcdn.com/ajax/4.6/1/MenuStandards.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/4.6/1/WebUIValidation.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/4.6/1/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
(window.Sys && Sys._Application && Sys.Observer)||document.write('<script type="text/javascript" src="/ScriptResource.axd?d=D9drwtSJ4hBA6O8UhT6CQjaBRU6Z6H7p9O0STLSLg5rBf8PmRnl4mgvaWhIMV_ez6XMoUIIKH0Lvyft9wMx-mn1K9xpgrT3p2SyaN0NhYQbdjgaFJ6SvDdyemGdHEucpaI3wWXBGiOlLSdsFNYsvmTOODx6pVaODE03NGxR7Xbg1&t=ffffffffcc58dd65"><\/script>');//]]>
</script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>
<script src="http://ajax.aspnetcdn.com/ajax/4.6/1/MicrosoftAjaxWebForms.debug.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
(window.Sys && Sys.WebForms)||document.write('<script type="text/javascript" src="/ScriptResource.axd?d=JnUc-DEDOM5KzzVKtsL1tS1fIGeXSMhL5jVbdlHHyfSurUpuo1S171n76BLe9kDe1bp92aRTLPrikgb1IAtAszNWAFCy6sKP29VeCOzcPlox9DtzCzUFdGq4Fy-s27Drv30WWrzbTeErZ2yuWIvEzeuzvitKK3msQe9zpZo5Og0E5fjP9jHIPtUi3ZaZxHQF0&t=ffffffffcc58dd65"><\/script>');//]]>
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.2.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
(window.jQuery)||document.write('<script type="text/javascript" src="../Scripts/jquery-2.2.2.js"><\/script>');function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
On page 400 of your book in the
TRY IT OUT: Unobtrusive JavaScriptValidation step 9, you add a reference to â~/Scripts/WebForms/WebUIValidation.
jsâ on the master page. However, this reference is missing in the download code for the site. In my scriptmanager I also didnât include this reference as shown above; however, as you can see in the page source view above the CDN source is referenced for WebUIValidation.
js. Why is this reference not needed?
Thanks for the great book and taking the time to reply!