[Solved] ASP.Net Ajax Error: Sys is undefined

ramco1917
 
on Oct 07, 2022 12:52 AM
Sample_177617.zip
694 Views

Hi

SCRIPT5022: ASP.NET Ajax client-side framework failed to load.

SCRIPT5009: 'Sys' is undefined

SCRIPT1003: Expected ':'

<script>
    $("#ddlTrainingType").change(function (e) {
        $.ajax({
            url: "TrainingReport.aspx/BindTrainingModule",
            data: '{"Id": + $(this).val() }',
            debugger;
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            success: function (result, status, xhr) {
                $("#lstTrainingModule").html(result.d);
            },
            error: function (xhr, status, error) {
                alert("error0");
                alert("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
            }
        });
    });
</script>

 

<appSettings>
    <add key="FolderPath" value="../Files/" />
</appSettings>
<system.web>
    <compilation debug="true" targetFramework="4.6.2" />
    <httpRuntime targetFramework="4.6.2" />
    <pages>
        <namespaces>
            <add namespace="System.Web.Optimization" />
        </namespaces>
        <controls>
            <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
        </controls>
    </pages>
    <authentication mode="Forms">
        <forms name="TRGForm" loginUrl="Index.aspx" />
    </authentication>
    <httpHandlers>
        <!--<add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>-->
        <add verb="GET"  path="ScriptResource.axd"  type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
    </httpHandlers>
</system.web>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>
<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
</system.codedom>
<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
        <remove name="WebServiceHandlerFactory-Integrated"/>
        <remove name="ScriptHandlerFactory"/>
        <remove name="ScriptHandlerFactoryAppServices"/>
        <remove name="ScriptResource"/>
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>
</system.webServer>

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Oct 07, 2022 09:05 AM

Hi ramco1917,

Check the example.

Database

For this example I have used of Northwind database that you can download using the link given below.

Download Northwind Database

HTML

<asp:DropDownList ID="ddlCountries" runat="server">
    <asp:ListItem Text="Please select"></asp:ListItem>
    <asp:ListItem Text="France"></asp:ListItem>
    <asp:ListItem Text="Germany"></asp:ListItem>
    <asp:ListItem Text="Canada"></asp:ListItem>
</asp:DropDownList>
<hr />
<asp:ListBox ID="lstCustomers" runat="server"></asp:ListBox>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $('#ddlCountries').change(function () {
        $.ajax({
            type: "POST",
            url: "Default.aspx/GetCustomers",
            data: '{country:"' + $(this).val() + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                var lstCustomers = $("[id*=lstCustomers]");
                lstCustomers.empty();
                $.each(r.d, function () {
                    lstCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
                });
            }
        });
    });
</script>

Namespaces

using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;

Code

[WebMethod]
public static List<ListItem> GetCustomers(string country)
{
    List<ListItem> items = new List<ListItem>();
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers WHERE Country = @Country"))
        {
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@Country", country);
            cmd.Connection = con;
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                items.Add(new ListItem { Text = sdr["ContactName"].ToString(), Value = sdr["CustomerID"].ToString() });
            }
            con.Close();
        }
    }

    return items;
}