1

I've been struggling with this for several hours and can't seem to figure out what is going or any relevant sites that pertain to this. All I'm trying to do is to use the Ajax Control Toolkit and JQuery at the same time.

Below is the only code needed to recreate my problem.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="TestWebsite.TestForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
        language="javascript" /> 
</head>
<body>
    <form id="form1" runat="server">
    <ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </ajax:ToolkitScriptManager>
    <div>

    </div>
    </form>
</body>
</html>

In case it matters I am using Visual Studio 2010 professional. My asp.net website is targeting the .NET 4.0 framework. I am using the AjaxControlToolkit.dll which has a version of 4.1.60501.0. Jquery is the 1.7.2 min version.

If I comment out either the jquery script line or the ToolkitScriptManager I don't get any javascript errors. If they are both included I get the error

"Microsoft JScript runtime error: Sys.ArgumentException: An element with id 'form1' could not be found. Parameter name: elementOrElementId"

Stacktrace is giving me the DomElement$resolveElement(elementOrElementId, containerElement) javascript function as the culprit.

Any help would be appreciated.

Dan P
  • 1,939
  • 3
  • 17
  • 30
  • not sure but you may have to add jQuery file as script resource in your toolkitscriptmanager. – Asdfg Jun 22 '12 at 19:27

2 Answers2

7

As rediculous as this sounds, change your script tag to be this:

<script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
        language="javascript"></script> 

Observe that I'm using a closing script tag (this is crucial).

Jeremy
  • 8,902
  • 2
  • 36
  • 44
  • Wow...what complete and utter malarkey. That did fix it...either that or my frustration and reboot fixed it :) – Dan P Jun 22 '12 at 20:29
  • 1
    btw any idea why the using the long form ending closing script fixes it? – Dan P Jun 22 '12 at 20:34
  • This specification should shed some light: [C.3. Element Minimization and Empty Element Content](http://www.w3.org/TR/xhtml1/#C_3). Personally, I say it's a bug :D – Jeremy Jun 22 '12 at 20:38
  • @DanP It's to do with the MIME type. See [porneL](http://stackoverflow.com/users/27009/pornel)'s [answer](http://stackoverflow.com/questions/97522/what-are-all-the-valid-self-closing-tags-in-xhtml-as-implemented-by-the-major-b#answer-206409) to the ["What are all the valid self-closing tags in XHTML (as implemented by the major browsers)?"](http://stackoverflow.com/questions/97522/what-are-all-the-valid-self-closing-tags-in-xhtml-as-implemented-by-the-major-b) question. – Adam Lynch Aug 03 '12 at 12:21
0

The element has the server-side id form1 you cannot use this id client-side. You'd have to use server-side property this.form1.ClientID to get the client-side it (something like ctrl00_form1). Or you could remove the runat="server" if you don't use to access the form server-side.

Edit:

I may misunderstood your question: If this code throws an exception, you may have to write the script tag this way: <script type="..." src="..."></script> (non-selfclosing but empty).

StrubT
  • 998
  • 5
  • 18
  • I don't have any code referencing form1. That's auto generated when you create a new aspx page and I can't remove the runat server as eventually that will break other code. This is the most basic default aspx page I could setup that is capable of reproducing the problem. – Dan P Jun 22 '12 at 19:47