Call Code Behind method in javascript on Focus of WebDropdown

Posted by Asifhussain under ASP.NET AJAX on 4/18/2012 | Points: 10 | Views : 7026 | Status : [Member] | Replies : 5
Hi,

I need to call a code behind Method from javascript which is used to bind invoice no based on Job ID which is a Foreign key. Below is the code which is used for calling, while the asp.net page is loaded for the first time, this is working fine. Here the problem is LoadInvoiceForJob is a method which is called in javascript, which is as follows:

function LoadInvoiceJobs() {
var e = document.getElementById('<%= txtRefDocID.ClientID %>').value;
if (e > 0) {
callInv();
}
}
function callInv() {
'<%= LoadInvoiceForJob() %>';
}


below is the code behind, if i run this page return empty string while page is loaded first time, the script is showing me the empty value on html page source too. But when i try to send the string as <%= LoadInvoiceForJob %>, this is not doing any action. txtRefDocID holds a value, which is hidden control

protected string LoadInvoiceForJob()
{
LoadInvoiceNo(txtRefDocID.Value);
return "<%= LoadInvoiceForJob(); %>";
}

private void LoadInvoiceNo(string JobID)
{
cmbInvoiceNo.Items.Clear();
cmbInvoiceNo.SelectedItemIndex = -1;

DataTable dt;
dt = new DataTable();
dt = _Inv.GetInvoiceNoByJob(JobID);
cmbInvoiceNo.TextField = "InvoiceNo";
cmbInvoiceNo.ValueField = "InvoiceID";
cmbInvoiceNo.DataSource = dt;
cmbInvoiceNo.DataBind();
cmbInvoiceNo.CurrentValue = "";
}


Any help would be appreciated.

Thanks in Advance!!




Responses

Posted by: Asifhussain on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
I forgot to mention another thing, i have place web drop down under Update Panel and AjaxToolKit ScriptManager is used here.

Asifhussain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/18/2012 [Member] Bronze | Points: 25

Up
0
Down
Call it using pagemethod.

Thanks,
Rajni Shekhar

Asifhussain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Asifhussain on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hello Rajni,

I tried calling it thru PageMethods, but that is throwing me an microsoft jscript runtime error pagemethods is undefined.

Thought added EnbalePageMethods="true" in ToolkitScriptManager, still the problem exist.

Asifhussain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/18/2012 [Member] Bronze | Points: 25

Up
0
Down
Are you using PageMethods inside a function body?
Have you included reference of AjaxControlToolkit.dll?


Thanks,
Rajni Shekhar

Asifhussain, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Asifhussain on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
Yeah AjaxControlToolKit is referenced, nope am calling PageMethods from code behind thru function body

Asifhussain, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response