Click to See Complete Forum and Search --> : ajax serverside call issues c# user control


DARTHTAMPON
11-12-2008, 12:54 PM
So I am trying to make a call to a serverside function.

the html


<script type="text/javascript">
/// <reference name="MicrosoftAjax.js"/>

function filterDBResults(variable)
{
alert(variable.value);
// call server side method
PageMethods.filterDBResults(variable.value, CallSuccess);
}
// set the destination textbox value with the ContactName
function CallSuccess(res, destCtrl)
{
var dest = document.getElementById(destCtrl);
clearlistbox(dest);
var packages = [];
var packages = res.toString().split(/,/);
for (var x = 0; x < packages.length; x++)
{
var opt = document.CreateElement("OPTION");
opt.text = packages[x];
dest.options.add(opt);
}

}
// alert message on some failure
function CallFailed(res, destCtrl)
{
alert(res.get_message());
}

//Remove all items from a listbox and clear any selections
function clearlistbox(lb)
{
for (var i=lb.options.length-1; i>=0; i--)
lb.options[i] = null;
lb.selectedIndex = -1;
}

</script>

<asp:scriptmanager id="ScriptManager1" runat="server" EnablePageMethods="true" />


<asp:label runat="server" text="searchLabel" id="lblSearchFor"></asp:label>
<asp:textbox runat="server" id="txtSearchBox"></asp:textbox>
<br />
<asp:listbox id="lbPackages" runat="server" visible="False"></asp:listbox>


serverside

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
this.txtSearchBox.Attributes.Add("onkeyup", "javascript:filterDBResults(this)");
}

[System.Web.Services.WebMethod]
public static string filterDBResults(string searchWith)
{
string packages = "";
DataSet ds = new SLIMOnline.Utilities().grabTheSLIMDB().getDataSet("exec SP_SLIM_find_package '" + searchWith + "'");
foreach (DataRow dr in ds.Tables[0].Rows)
{
packages += "[" + dr["PackageID"] + "] " + dr["publisher"] + " " + dr["Application"] + " " + dr["version"] + ",";
}
return packages;
}



Unfortunatly I get this error at the red, boded part in the html
Microsoft JScript runtime error: 'PageMethods' is undefined

At this time I am completly out of ideas. I am using VS 2008.

Any thoughts on how I can fix this. I have also tried sticking it into an ajax master page but the same error exists there as well.


tia

chazzy
11-12-2008, 04:42 PM
well, what's pagesmethods supposed to be? unfortunately, c# doesn't expose all methods in a page class as javascript objects/functions, you need to do part of it.

DARTHTAMPON
11-12-2008, 09:46 PM
according to the documentation the pagemethod stuff should be generated with this line of code

<asp:scriptmanager id="ScriptManager1" runat="server" EnablePageMethods="true" />


Most of this information was based off of a microsoft tec-ed conference slide show.

I am just not sure how all the nuts and bolts need to go together.

chazzy
11-13-2008, 05:20 AM
what version of .net are you using? you might want to look here: http://msdn.microsoft.com/en-us/library/bb398822.aspx as you might be using asp.net ajax 1.0 styles in a newer version.