I have a Page where I have to show search results on the basis of selected options.
I am showing the results in a Repeater control. We have several (more than 20) search conditions (different dropdown lists). On the basis of selected condition, I have to bind the search results.
Till now, we was using the Update Panel. As we bind records according to selected condition & these controls are more then one. I placed all controls in a Update Panel & repeater in another update panel. It was working fine but this process was slow because
in case of update panel, all data goes to server.
So, I have decided to use AJAX call to get search records. For this purpose, I have created a new page(suppose dosearch.aspx) where I placed my repeater control only.
I have written a jquery AJAX call in dropdown's onchange event. I catch the selected value & I am calling that new page(dosearch.aspx) to get search data. As I have placed the repeater in that page(dosearch.aspx), so accoding to dropdown's selected value,
I fetch records from database & bind the repeater control.
Till here, everything is fine. My Problem starts now. As I am binding the repeater control in dosearch.aspx page & I cannot use Response.write() to write the "ONLY REQUIRED" data to output stream. This complete page renders & it sends the complete Page's
html (including HTML tags, body & other .net geneated codes) to ajax call response.
I just want the data which I have bound for the repeater control. Is there any way to write only Repeater control's rendered data to output stream? Or is there any other way to get Repeater's data?
While this is trivial in MVC, in webforms it's a little tricker. The simplest is a new page that the Ajax calls. You could also make a user control that's just the list and use from both the main page and the Ajax page.
Thanks for your reply. Yes, I can also use same user control in both main page & ajax page.
But this will not solve the problem. After all, we will call the page & after rendering, I will get complete rendered html.
You said that "in webforms it's a little tricker".
Can you please guide me, HOW ?
If there is no solution of above problem, then I can think about a second option. I can return the JSON & then I will bind (create HTML) on client side.
But I really hate to create dynamic HTML. Is there any good/efficient TEMPLATE based solution?
But my first priority is still the previous one. because along with search records, i also have to show paging buttons (1 2 3 4 etc) & some other custom tabs too.
anujrathi
Member
193 Points
113 Posts
How to access Page response in Jquery Ajax (GET/POST) call
Feb 16, 2013 05:53 PM|LINK
Hi friends,
I have a Page where I have to show search results on the basis of selected options.
I am showing the results in a Repeater control. We have several (more than 20) search conditions (different dropdown lists). On the basis of selected condition, I have to bind the search results.
Till now, we was using the Update Panel. As we bind records according to selected condition & these controls are more then one. I placed all controls in a Update Panel & repeater in another update panel. It was working fine but this process was slow because in case of update panel, all data goes to server.
So, I have decided to use AJAX call to get search records. For this purpose, I have created a new page(suppose dosearch.aspx) where I placed my repeater control only.
I have written a jquery AJAX call in dropdown's onchange event. I catch the selected value & I am calling that new page(dosearch.aspx) to get search data. As I have placed the repeater in that page(dosearch.aspx), so accoding to dropdown's selected value, I fetch records from database & bind the repeater control.
Till here, everything is fine. My Problem starts now. As I am binding the repeater control in dosearch.aspx page & I cannot use Response.write() to write the "ONLY REQUIRED" data to output stream. This complete page renders & it sends the complete Page's html (including HTML tags, body & other .net geneated codes) to ajax call response.
I just want the data which I have bound for the repeater control. Is there any way to write only Repeater control's rendered data to output stream? Or is there any other way to get Repeater's data?
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: How to access Page response in Jquery Ajax (GET/POST) call
Feb 16, 2013 09:25 PM|LINK
anujrathi
Member
193 Points
113 Posts
Re: How to access Page response in Jquery Ajax (GET/POST) call
Feb 17, 2013 02:02 AM|LINK
Hi Bruce,
Thanks for your reply. Yes, I can also use same user control in both main page & ajax page.
But this will not solve the problem. After all, we will call the page & after rendering, I will get complete rendered html.
You said that "in webforms it's a little tricker".
Can you please guide me, HOW ?
If there is no solution of above problem, then I can think about a second option. I can return the JSON & then I will bind (create HTML) on client side.
But I really hate to create dynamic HTML. Is there any good/efficient TEMPLATE based solution?
anujrathi
Member
193 Points
113 Posts
Re: How to access Page response in Jquery Ajax (GET/POST) call
Feb 17, 2013 02:19 AM|LINK
Hi Bruce,
I have found the jquery templete solution.
http://www.borismoore.com/2010/09/introducing-jquery-templates-1-first.html
But my first priority is still the previous one. because along with search records, i also have to show paging buttons (1 2 3 4 etc) & some other custom tabs too.
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: How to access Page response in Jquery Ajax (GET/POST) call
Feb 17, 2013 07:25 PM|LINK
I don't understand your question. the ajax page should have only the html you want returned.
('#searchResults').load('ajaxpagename.aspx);
if you need to update more than 1 div, then build the dom, and get components
$.ajax(url, function(r) { var $r = $(r); $('div1').html($r.find('div1').html()); $('div2').html($r.find('div2').html()); });you can also use json and client templates, there are several template libraries.
crowcoder
Participant
1857 Points
345 Posts
Re: How to access Page response in Jquery Ajax (GET/POST) call
Feb 17, 2013 09:06 PM|LINK
JQuery templates is deprecated. Use JSRender.
https://github.com/BorisMoore/jsrender
and how to use it:
http://msdn.microsoft.com/en-us/magazine/hh882454.aspx
var MyMagic = MagicCode.ReadMyMind();
MyMagic.DoWhatImThinking();
www.ContrivedExample.com