PDA

View Full Version : Extjs and ASP.NET



hieu79vn
26 Apr 2012, 2:48 PM
Hello

I have asked this question but haven't receive a suitable answer so I repost it.
I have a grid panel and each time user click on a row of grid I will call to server to get detail data of this row.
Really I can create an blank aspx web page and return a string in json format with Response.Write
and call url:<path>/page.aspx?id=5

But really I don't know if there is another way to do this. Please do not suggest using a thirdparty control because I think it makes messy my code.

I see that Ext.Direct or proxy can solve this problem easily but I havent known how to use them yet. It's very kind if you can give me an example

Thank you

vietits
26 Apr 2012, 3:59 PM
You could use Ext.Ajax.request(). Example:


grid.on({
itemclick: function(view, record){
Ext.Ajax.request({
url: '/page.aspx',
params: {
id: record.getId()
},
success: function(response){
// your code to handle successful response
},
failure: function(response){
// your code to handle failed response
}
})
}
})

webfriend13
26 Apr 2012, 6:45 PM
Hi,

Please provide more details about your implementation. How are you displaying the result after clicking on the row? Make use of Ext.Ajax.request to make call to the sever.

hieu79vn
26 Apr 2012, 11:18 PM
Hi,

I do like yahoo mail. You click on a row of grid and I will show the detail of this row below the grid.

@vietits: One more question. So in the page.aspx, I should return a string in json format. But my proplem is that this aspx page is not a blank page. It contains the decorated frame, menu.
I'm thinking if url can refer to a function or a variable on server?
Do you have an example of your page.aspx and page.aspx.cs

Many thanks

vietits
26 Apr 2012, 11:34 PM
In Ext.Ajax.request(), url is what you should fill in for the request sent to. In my post, '/page.aspx' is just an example.

hieu79vn
26 Apr 2012, 11:38 PM
I found the code below. It seems that it responses to my question. After the name of page is a name of function which return a json string


/// &lt;summary&gt;/// Default.aspx/// Reads JSON like {param1: 'test'}/// Returns JSON like {param1: 'test' }/// &lt;/summary&gt;[WebMethod(EnableSession = true)]public static Dictionary&lt;string,object&gt; Test( string param1 ){ Dictionary&lt;string,object&gt; ret = new Dictionary&lt;string,object&gt;(); ret.Add("param1",param1); return ret;}in .js file
Ext.Ajax.request({ url: '/Default.aspx/Test' // this is the trick , jsonData: { param1: 'test' } , callback: function() {} , failure: function() {} , success: function(response) { // Read JSON var data = Ext.JSON.decode(response.responseText); alert(data.param1); // "test" }}); // eo Ajax

webfriend13
30 Apr 2012, 12:43 AM
I found the code below. It seems that it responses to my question. After the name of page is a name of function which return a json string


/// &lt;summary&gt;/// Default.aspx/// Reads JSON like {param1: 'test'}/// Returns JSON like {param1: 'test' }/// &lt;/summary&gt;[WebMethod(EnableSession = true)]public static Dictionary&lt;string,object&gt; Test( string param1 ){ Dictionary&lt;string,object&gt; ret = new Dictionary&lt;string,object&gt;(); ret.Add("param1",param1); return ret;}in .js file
Ext.Ajax.request({ url: '/Default.aspx/Test' // this is the trick , jsonData: { param1: 'test' } , callback: function()
{} , failure: function() {} , success: function(response) { // Read JSON var data = Ext.JSON.decode
(response.responseText); alert(data.param1); // "test" }}); // eo Ajax


Please add your code using proper TAGS. The code would be readable that way. Thank you for posting the solution.