In my site, I'm using update panel in the master page. Half of my web page will retrieve the data from the database in dynamic. As, my update panel is in master page(with ajax loader), it is taking much time for every event. Is there any other advanced method to get the data from the database instead of using update panel.. Or any other idea instead of this?
I think you need to profile to see where the bottleneck is; I expect you have unnecessary code going on in your aspx that isn't really needed for the UpdatePanel.
Personally, I wouldn't use UpdatePanel now; I'd use a simple (but separate) page (or route, if using MVC) that just does the code needed for this work, and use jQuery to load it.
I think you want to load your web page from database table which contains html. If it is so then the best idea would be to create controls for headers/ footers or repeated sections and use caching which would reduce the load time of your web pages.
You could easily cache your controls. You can check here http://msdn.microsoft.com/en-us/library/aa478965.aspx
Happy coding
Related
I have repeater control in which i am binding data from sql server database, Now i have number of records showing on my page but i want that i can filter my records according to dropdown selected. I need 4-5 dropdowns control thats depend on my need and i don't want my page to refresh while filtering.
Below is the example, this website using checkboxes too but i need only dropdowns...
http://www.phonearena.com/phones/full#/phones/full/
Give me any idea how to start, i think ajax is the thing i need. Suggest some examples if you have.
Ajax is the right solution.
Personally i suggest you jquerytemplate and ajax call few row code to achive your goal you may find more info here Load JSON data using the dropdown menu and refresh the div area with the new results in a web site
It is a good point to start and you can make more stuff with this logic :) really simple and fluid code :)
I would suggest you to use a client-side framework (so in JavaScript) like AngularJS, BackboneJS or KnockoutJS. They all provide ways to work with collections in JavaScript (like filtering in this case). You won't need Ajax excepted for the first load or if you want to do some paging. And because it's all client-side it will be far more fluid than re-downloading at every criteria change.
I have created web page that retrieves data from MS SQL database and display it to the user in well formatted manner. Data retrieved depend upon criteria selected by the user. But sometimes data retrieved is very large. I want to display records to the user page wise, i.e. 100 records on first page and next 100 records displayed when user clicks next button. This means only 100 records should be retrieved when user first select search criteria, next 100 records retrieved when he clicks next button and so on, as to reduce data transferred from server to client.
Please suggest me how to achieve this as soon as possible. Thanks in advance.
What you are looking for is called paging.
This can be done a million ways. You mention jquery, javascript and asp.net. For displaying purpose that is quite all righ but for good performance you want to make sure that the actual selection of the page has to be done at the backend.
One approach is this:
http://msdn.microsoft.com/en-us/library/aa479347.aspx This is not jquery but it shows a way to do it.
You can use jqGrid or DataTables. Both are very popular grids
Ask user to set there criteria and then render the grid according to that.
If you want simple fast and way then think in using jQuery plugins like these
jpaging OR datatables.
you should search for design pattern for this.
kindly look at this Easily build powerful client-side AJAX paging, using jQuery
Your use of both asp.net and C# makes me (probably because I am partial to it) think "WebMatrix". If, indeed you are using WebMatrix, check out its Grid Helper. However, be warned that this method can generate some very serious overhead for your html page (by that I mean that if you query 1,000 rows and only use 100 per page, it will retrieve all 1,000, use 100, and waste the other 900). Also, using the WebGrid generates the results in a table, which may not be your preferred style.
Alternatively (still thinking "WebMatrix"), you could use this article here (this is my preferred method): http://www.mikesdotnetting.com/Article/150/Web-Pages-Efficient-Paging-Without-The-WebGrid
Don't worry, that article is explained with EXCELLENT brevity and accuracy (and explained better than I could, so I leave it to Mike to vicariously answer that one).
I wrote a page which user can input a name and get some infos from the database. In the .cs file I got the texts from the database and assigned them to the labels and in the debugging mode, the labels did change their texts. BUT I don't know how to update them in the same page. I used some ways to update the page, but it updated the whole page and display nothing in the labels.
How can I achieve this function?
I google it and found the AJAX is a good way, but it's an emergency i have no time to learn AJAX?
does someone have good idea to help me solve it?
Thanks a lot!
What you're talking about is a postback. When the page posts back to the server, the page is refreshed.
If you want to set the labels and avoid losing the data with a postback, you can do so through an ajax call in your JavaScript code, you can set hidden fields or you can set the values in the Session object (not the best idea). There are numerous ways around this; you just have to pick one.
Do some reading on ajax (it's not as hard as you think). You can call the server through ajax, which will get the data from the Db and return it to your JavaScript as JSON. You can then use that to fill your labels.
You may want to look into an UpdatePanel as well. They aren't the fastest solution available, but they are very easy to implement.
I ran into this problem multiple times in my career, and never was able to find a elegant solution for it. Imagine you have a simple page, that has a repeater. You populate that repeater on the server-side through the databinding. That's great, works fast and does what it's supposed to. But now you want to add paginator to that repeater, or otherwise change the output. Doing it through Ajax is a preferred way to enable rich client interaction.
So you create a web-service that serves you the data as JSON, but now you are stuck... Either you have to write complicated client-side code to find each field that you need to modify in each repeater-item, or you have to blow away the whole server-side output of the repeater and construct new HTML from the scratch, or, the method that I've been using lately, take the first repeated item, blow away everything else and clone the first item as many time as you need to and modify it's fields.
All of the described methods are not optimal, because no matter what, they require quite a bit of repeated logic on the server-side (i.e. template in repeater) and on the client-side (javascript to display JSON data). There's got to be a better, easier way to do this. First thing that comes to mind, is instead of returning JSON from the web-server, return HTML of the pre-populated repeater. But for something like that, I might as well use ASP.NET AJAX Update panel. The output isn't going to be any smaller with a stand-alone web-service.
Next thing that I thought of, is JavaScript templates. What if there would be some way to take unprocessed repeater template on the server-side, and convert it to JavaScript template that could be either embedded on the page at load, or served as part of the web-service response. However, I couldn't find any existing solutions for something like this. And I can't think of a simple way to do that myself. Any ideas?
P.S. Rendering JavaScript template to the client-side on page load, and using JavaScript to populate it without the initial view being rendered on the server (no repeater and databinding) is out of the question. I care too much about performance.
Firstly, I don't believe that using client template with JSON data even on first load will adversely affect the performance unless we are talking about devices with different form factors such as phones etc.
However, if you must use server side templating/rendering then why not make server return the html for the repeater. This can be done by putting repeater logic into a different user control/page and processing only that page on ajax request. And this is not at all equivalent to using UpdatePanel (as stated by you) - UpdatePanel posts entire page data (including view-state) having more request size. The response size is also larges because it must contain the view-state. On server side also, use of UpdatePanel results in loading complete control tree with state data and post-back event processing. Sending only the requisite html is much better approach and will fit your needs perfectly - only issue is the html would be larger in size as compared to JSON.
Lastly, there are some interesting projects such as Script# - Script# converts C# code into java-script. You may build something similar (using script# itself) to convert the server side templating code into eqivalent JS code. More viable approach on similar lines could be use T4 templating to convert a technology-agnostic template into both server side code (markup + code or pure code) and equivalent JS-code.
After thinking about all pros and cons of different approaches, I stopped on the following method. I created a custom ASP.NET databound control, that can render HTML, however, when the page is requested with query string parameters, instead of just doing standard rendering, it will use Response.Clear() and Response.End() and in between of those two commands output JSON version of data based on the query string parameters. Also on the first rendering of the page, it will also output JavaScript template using reflections to read names of the variables from the control's template area.
This method works great, all I have to do, is drop my control on the page, data bind it, and it works as a true AJAX grid that supports pagination, sorting and filtering. However it does have limitation. In the control's template you can only specify variables, not expressions. Otherwise reflections can't convert it to a JavaScript variable. But I can live with that.
Other possibilities that I considered is a separate web-service that takes a type of the page as parameter and uses reflection to get data bound object as well as create template for the grid. I also though about writting my own version of update panel, that would not use view state and only send in part of the page.
In my ASP.NET WebForms application, I have a WebForm that contains an UpdatePanel and multiple views used for a wizard like interface.
At the end of the wizard, the user has an option of moving to another page by clicking a button. This new web page needs about 5 values from controls in the previous page.
What is the simplest way to do this? (Edit: ONLY using an HTTP POST with data - this is a requirement as I would use database/session otherwise)
I tried using cross-page posting with no luck, possibly because of my update panel and multiple views?
I tried using Server.Transfer, but this also breaks because of the update panel.
Important:
Data has to be sent via HTTP POST - The data can't be stored anywhere
The scenario can't be changed. I can't put everything on the same page
The simplest way to do this is by putting those values in the session object.
You could make a class that describes the data that you need to display on the redirected page. Instatiate a new instance of that at the time the user is filling out the wizard data, populate the new classes' object with the information you need, then add it to the session in the button_Click event before page redirection. On the page you are redirected to, grab the Session object, put it into a variable and extract the data you need.
I recommend you combine all the relevant pages into one; hiding panels that are not in play. ASP.NET will maintain the values of all the controls for you from post to post. The Viewstate was designed for sceneries like you describe. To keep to Viewstate size to a minimum, make sure you fill lookup values for drop-down controls in their "Init" methods.
You don't want to use the session state. The last thing you want is for the users to loose their data from previous pages because they took too long to answer.
If they're moving to another page in the solution, you have a few options.
ViewState - The ViewState is sent with the page delivery. It resides in the HTML, but is encrypted so no one can see the information. Depending on the size of the information, your page size could get rather large.
Session - This puts the information client-side via cookies.
Query String - Using the URI. This should only be used if it's non-sensitive information and if you don't want a user to be able to link back to the same action again.