Monday, March 26, 2012

AJAX AutoPostBack not working...:(

Hi!

I've read a few posts about not working autocomplete, but I haven't found anything that would help me get my autocomplete in action. Here's my code and I hope someone can tell me what am I doing wrong...:

WebService:

<%

@dotnet.itags.org.WebServiceLanguage="C#"Class="WebService" %>

using

System;

using

System.Web;

using

System.Web.Services;

using

System.Web.Services.Protocols;

using

System.Web.Script.Services;

using

System.Web.Configuration;

using

System.Data.SqlClient;

using

System.Collections;

[

WebService(Namespace ="http://tempuri.org/")]

[

WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

public

classWebService : System.Web.Services.WebService {

[

WebMethod]

[

ScriptMethod]publicstring[] GetCompletionList(string prefixText,int count)

{

ArrayList list =newArrayList();

string connStringCompletionList =WebConfigurationManager.ConnectionStrings["NeolabConnectionString"].ConnectionString;SqlConnection connCompletionList =newSqlConnection(connStringCompletionList);

connCompletionList.Open();

SqlCommand cmdCompletionList =newSqlCommand("SELECT Seminar FROM Seminar ORDER BY Seminar;", connCompletionList);SqlDataReader rCompletionList = cmdCompletionList.ExecuteReader();while (rCompletionList.Read())

{

list.Add(rCompletionList.GetString(0));

}

string[] completionList = (string[])list.ToArray(typeof(string));return completionList;

}

}

(WebService looks to work just fine, it creates an XML filled with all items)

The page (actually it's a control)

<%

@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="SeminarjiFilter.ascx.cs"Inherits="UC_I_SeminarjiFilter" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

<

asp:ScriptManagerID="ScriptManager1"runat="server"/>

<

h1>Filter</h1>

<

divclass="crta"></div><tablecellpadding="0"cellspacing="0"border="0"width="100%"runat="server">

<tr><td>

Seminar:

</td><td><cc1:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"TargetControlID="TextBox1"ServiceMethod="GetCompletionList"ServicePath="/WebService.asmx"MinimumPrefixLength="2"CompletionInterval="1000"EnableCaching="true"CompletionSetCount="12"></cc1:AutoCompleteExtender><asp:TextBoxID="TextBox1"runat="server"CssClass="input"AutoCompleteType="Disabled"/></td></tr>

Can anyone help me? I just can't find what am I doing wrong.

Thx!

p.s.: I'm using Visual Studio Web Developer 2005

Your webservice needs a ScriptService attribute. You do not need the ScriptMethod attribute on the method since this is not a page method.

Hi kirtid!

thx for your help, but it's still not working :(

I've added a ScripService attribute like you have suggested, so my WebService.asmx looks like that now:

<%

@.WebServiceLanguage="C#"Class="WebService" %>

using

System;

using

System.Web;

using

System.Web.Services;

using

System.Web.Services.Protocols;

using

System.Web.Script.Services;

using

System.Web.Configuration;

using

System.Data.SqlClient;

using

System.Collections;

[

ScriptService]

[

WebService(Namespace ="http://tempuri.org/")]

[

WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

public

classWebService : System.Web.Services.WebService {

[

WebMethod]publicstring[] GetCompletionList(string prefixText,int count)

{

ArrayList list =newArrayList();

string connStringCompletionList =WebConfigurationManager.ConnectionStrings["NeolabConnectionString"].ConnectionString;SqlConnection connCompletionList =newSqlConnection(connStringCompletionList);

connCompletionList.Open();

SqlCommand cmdCompletionList =newSqlCommand("SELECT Seminar FROM Seminar ORDER BY Seminar;", connCompletionList);SqlDataReader rCompletionList = cmdCompletionList.ExecuteReader();while (rCompletionList.Read())

{

list.Add(rCompletionList.GetString(0));

}

string[] completionList = (string[])list.ToArray(typeof(string));return completionList;

}

}

I do get a JavaScript error in Firefox, which says:

Napaka: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::http://localhost:1952/CISEF/ScriptResource.axd?d=jhPPdebJMXZyNg9DlOLOhTS0Nid4TBhKPJdnm84vbDCB2-uUy_FSlPcxjsG2hmQvG2-MIlmaqMJ-KsoNz2f43LUv6JMplLSpW_hbE2koLH81&t=633108756900118528 :: Sys$Net$XMLHttpExecutor$get_statusCode :: line 4166" data: no]

Here's where it happens (file ScriptResource.axd):

function Sys$Net$XMLHttpExecutor$get_statusCode() { /// <value type="Number"></value> if (arguments.length !== 0) throw Error.parameterCount(); if (!this._responseAvailable) { throw Error.invalidOperation(String.format(Sys.Res.cannotCallBeforeResponse, 'get_statusCode')); } if (!this._xmlHttpRequest) { throw Error.invalidOperation(String.format(Sys.Res.cannotCallOutsideHandler, 'get_statusCode')); } return this._xmlHttpRequest.status; }
 
Any idea maybe?!?

Is the path to your webservice set in the ServicePath property correct? -> "/WebService.asmx".


Hi kirtid!

Sorry for late reply, I was on vacation :) Thanks for your help! It was a problem in a path like you assumed!

Later

No comments:

Post a Comment