Madison C. Brewer Madison C. Brewer - 1 month ago 13
ASP.NET (C#) Question

ASP conundrum (how to resolve)

Okay, so I'm using validation controls on a website

At first I was getting the classic error

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).


Didn't take much to fix that.

I added the following to my web.config file

<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="none"/>
</appSettings>


However, now when I run my pages, my asp:LinkButtons don't work correctly, their code-behind doesn't seem to execute (it's a school assignment so I can merely alter them to anchors. Guidelines mandate asp:LinkButtons).

I tried

<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms"/>
</appSettings>


But then I get the old error and my page won't load.

:/ I'm very confounded. What can I do?

EDIT: something possibly worth noting

My asp linkbuttons only malfunction in pages that also possess asp validators.
My other pages with asp link buttons work just fine.

Answer

Using this informative post from the MSDN blog

Add the following to your Global.asax file at the root of your web project:

protected void Application_Start(object sender, EventArgs e)
{
    string str = "1.7.1"; //Change to the version of jQuery you require
    ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
    {
        Path = "~/Scripts/jquery-" + str + ".min.js", 
        DebugPath = "~/Scripts/jquery-" + str + ".js", 
        CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + str + ".min.js", 
        CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + str + ".js", 
        CdnSupportsSecureConnection = true, 
        LoadSuccessExpression = "window.jQuery"
    });
}

Place the following in your Master page or on each page that uses the validation controls:

<asp:ScriptManager runat="server">
    <Scripts>
        <asp:ScriptReference Name="jquery" />
    </Scripts>
</asp:ScriptManager>