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
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