View Full Version : ExtJs3.1 web service problem

26 Feb 2010, 10:12 AM
I am using asp.net (framework 3.5) and extjs 3.1.
Now I have faced a problem when using web Method.In my project AdminPanel.aspx contains web method PopulateDistrict, but when change a combobox select its not working, if I change the url like test.aspx it works. what is the problem in asp.net I can use web Method() in same page just using attribute[web Method()]...

In my AdminPanel.aspx i wrote the following .....

var proxy = new Ext.data.HttpProxy({
url: "AdminPanel.aspx/PopulateDistrict",

var dstore = new Ext.data.JsonStore({
autoLoad: true,
url: "AdminPanel.aspx/PopulateDistrict",
proxy: proxy,
baseParams: { CountryID: 'Financial' },
fields: ['Id', 'cid', 'name'],
id: 'Id',
root: 'd'

ar ComboCountry = new Ext.form.ComboBox({
store: new Ext.data.ArrayStore({
fields: ['Id', 'name'],
data: CountryArray
}), //direct array data
transform: 'cmbCountry',
valueField: 'Id',
displayField: 'name',
mode: 'local', //it means data get from this page
typeAhead: true,
triggerAction: 'all',
emptyText: 'Select a Country...',
selectOnFocus: true,
listeners: //for call the event of the control
select: //here call the select event of combo
fn: function(combo, value)//here combo means cmbCountry
var comboDistrict = Ext.getCmp('cmbDistrict');
comboDistrict.clearValue(); //clear the previous value
params: {
pattern: combo.getValue()
}); //get the country id in cid parameter for filter

can any one help me? I am new in this field.

26 Feb 2010, 10:58 AM
What you describe (using the [WebMethod] attribute, etc) is not how ext works. This model is tied to the MS ajax framework. In general, Ext is not concerned with how to address a specific function in your .net code or any code for that matter. You will need to modify your code to handle the request parameters and route to the desired function, or use Ext.Direct. I will respectfully suggest that you check the docs, tutorials and examples, in particular the ones about using Ext with .Net.

27 Feb 2010, 7:32 AM
You need follow some rules to work with webmethods...
Assume you have a webmethod like this:

<Web.Services.WebMethod(True)> _
Public Shared Function PopulateDistrict(ByVal CountryID As String, ByVal pattern As String) As List(Of Dictionary(Of String, String))
Dim result As New List(Of Dictionary(Of String, String))

For i As Integer = 1 To 10
Dim item As New Dictionary(Of String, String)
item.Add("Id", i.ToString)
item.Add("cid", i.ToString)
item.Add("name", "foo")

Return result
Catch ex As Exception
Throw ex
End Try

1 - this method must be shared (or static in c#)
2 - We have "CountryID" and "pattern" parameters, so if you define any parameter in you webmethod, you will send this parameters always, otherwise .NET framework will throw an exception.

So, add parameter "pattern" in your baseParams

baseParams: { CountryID: 'Financial',pattern : null },

and now we need post parameters in a json format, so just add listener in your store (I dont know if there is other away to do it)

listeners: {
beforeload: function(store, options) {
options.params.jsonData = Ext.encode(options.params);

hope this helps!!!

27 Feb 2010, 8:56 PM
fabio,yes you get the point,Thanks a lot for your reply and guilde line.

My extJs code in AdminPanel.aspx and my Web Method() also in AdminPanel.aspx.
I have used this type of work with jquery, but in extjs web method is not working.

If I placed the web method in another page ClientEnd.aspx or servic ClientEnd.asmx then it works.

In same page not working can you give me any guide line?
sorry for bad english.

2 Mar 2010, 9:33 AM
ahsan, are you using firebug to see what error you are getting ?

2 Mar 2010, 8:26 PM
I have solved the problem with asmx page, pageMethod problem not solved.
Thanks to all for help.