asp.net calendar is too slow on OnDayRender - c#

I have a calendar in my asp.net application. OnDayRender I need to bind a value for each specific day from the database. So, I establish a connection to the db for each day. And, this slows down the system a lot. What would be a better way of doing this? How can I get these data for all month at once and display it appropriately?
Thanks!

Instead of doing the database query in OnDayRender, do it when your form initially loads, and fetch the data for the whole month (or whatever the range of the calendar is) into a List or something similar. Then your OnDayRender code can just fetch the data from the list.
It's hard to say more than that without a better idea of what you're doing, but that's the gist of it: fetch all the relevant data from the database into memory at the start, and then grab individual days from memory when you need them.

Related

ASP.net Schedule Post like Facebook

Im trying to do something similar to the Scheduling of posts for Facebook pages... on ASP.net/c#
So basically what i need is :
User fills a few text boxes
Selects a date...
The post gets posted on that date...
I am unable to really understand the logic as well as coding for this...
What i have thought so far is, once the user submits the post, store the details in a table in SQL like SheduledPosts, and when the CurrentDate(Server Date) matches the date....
Transfer the SQL entry from there to the actual PostTable.
Now the actual process needs to take place without any pages loading or any actions done by the user... So I also dont understand how to make it happen from the server side...
Please note that im not trying to post anything to facebook... rather, trying to do a schedule form submitting on my own asp.net website...
Any help regarding the logic, coding, scheduling will be greatly appriciated...
Thank You
I can think of a couple of different ways to accomplish this:
Implement a "pending posts" table and have a separate process running on the server to take care of transferring the post from the "pending posts" table to the "current posts" table at the appropriate time.
Add a "publish_on" datetime field to your current posts table, and when selecting items to be displayed in the page output, add a "WHERE publish_on IS NULL OR publish_on > GETDATE()" clause to your query. You fill this in for posts you don't want going live until a particular time.
Personally, I would go with the second approach, since I think it's a more elegant solution.
You can do this with one table. Just have a 'Submitted' date field (for your records), a 'Publish' date field and a Boolean 'Published' field. Create a Windows Service to run every 5 minutes or so and let the service perform the date check; when it finds one that satisfies the date criteria, it just toggles the Boolean field to 'true' and your page logic can then display the post.
Here is a walk-through on creating a simple Windows Service:
https://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Is a Database Needed Behind My ASP Site

I am building a website Asp.Net/C# and one component has a schedule with the AJAX Calendar Extender that puts the selected date in a text box, of course. I also have an AJAX Time Picker pick a time in another box.
However, I'm feeling a little ambitious; I want it where if someone selects say... July 25th, 2014, at like 1:30 PM, I want it to throw back a message on selection that the block of time is already selected. The time intervals run every 15 mins apart (i.e., 1:00, 1:15, 1:30, and 1:45).
I'm thinking I need a database behind the site to hold this, maybe SQL Server or would a lightweight Access workup due? My though is that it will hit the database and check for a duplicate instance of the select date and time slot, chosen by the user - then report back if it gets a hit... otherwise, it will populate the date and time text fields in the form.
It's for a small yard service company that makes out calls, but I wanna test and push myself. Any advice and structure suggestions from some seasoned pros who would be greatly appreciated. Thanks. Let me know if I need to provide more details.
If you do not have a database holding the data, where will you store the booked time slot? Where you plan to store your login information like user acc/password.
Of course you can store into text file but I would suggest a light DB like access. It would be enough for you to store few tables with not many line of data.
I do not see any problem with your taught to verify the data again what you stored in db. It should be the way.

Display records page wise using ASP.NET with C#

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).

Storing variable number of items in a database

I am using ASP.NET and Razor to create a calendar application similar to Google calendar and was hoping to get some feedback on my design thus far. My idea is to have 2 tables, one normal table for users, and another for a table of events which will store the users id and the time of the event, event ID, name of the event, and duration of the event.
I plan to write some code that will display a calendar on screen and allow the user to select multiple times so as to mark them as busy and give them a name. When this is done, the user submits the information and it is inserted into the database.
What is the best way to go about tackling this calendar construct? I can't really think of a simple way. I am guessing I can create a nice looking calendar using HTML and CSS, and perhaps JS to allow the drag and drop functionality? I suppose when the user selects a time, an object would be created with a start time and default duration, then when they drag it the duration changes. I am confused by how you would do this however, pulling objects out of thin air. How does Google Calendar do this?
And then how do you store all of the created objects in the database? I am guessing that Razor has a foreach construct and that I could just iterate over all objects created and insert them into the database one-by-one?
Also, how could I clean up the database, garbage collecting events that have already transpired while keeping events that are constant ie daily/weekly?
Apologies if the question is vague, if it is too vague then please press me on details I can be more clear on rather than close this. Thank you.
What is the best way to go about tackling this calendar construct?
If you are wondering about data structure here, whatever you do, do it in that way that it makes it compatible with standard iCalendar standard
I can't really think of a simple way.
Calendars are quite complex applications, there is no simple way. (events, sharing events, tentative, attendants, reminders...)
I am guessing I can create a nice looking calendar using HTML and CSS, and perhaps JS to allow the drag and drop functionality?
Yes.
I suppose when the user selects a time, an object would be created with a start time and default duration, then when they drag it the duration changes. I am confused by how you would do this however, pulling objects out of thin air. How does Google Calendar do this?
You can find some existing jquery plugins for this (try with this for start, or take a look at this list).
And then how do you store all of the created objects in the database? I am guessing that Razor has a foreach construct and that I could just iterate over all objects created and insert them into the database one-by-one?
Check out these jquery plugins and see how do they communicate with the server side. You will end up making ajax requests and then making database queries in the database. Razor has nothing to do with database...also Razor has nothing to do with client side interaction, it just renders page and everything else is on the js side.
Also, how could I clean up the database, garbage collecting events that have already transpired while keeping events that are constant ie daily/weekly?
I would't delete anything from database...don't see a reason for that. Just grab all you have and fill in the calendar. User will always look at month/date/week...grab data for that period and show it. When he goes back one year, he will have all the data still available.
Have you met my friend, Google?
In particular, 4GuysFromRolla has a tutorial, and there is a nice looking open source calendar control with some tutorials that should get you well on your way.

How to display thousands of records?

Hi
Let's say that I've to list thousands of records for my client.
How should I implement this? Some say that I have to retrieve just 300 or 400 records from the database and show those to the client. But I think there will be some problem with pagination. If I get all records from the database then I will have a performance problem. Some say to implement our own store procedure. How should I do this?
Thanks
You definitely have to use paging and not retrieve all the records at once, I recommend using some ORM tool to abstract the complexity of the required query for paging, if using LINQ it would be something very simple: ...Skip((pageNo-1)*pageSize).Take(pageSize)
I am in favor of sending ~100 records with the page, paginating through them by JavaScript, and retrieving further records in a batch by some higher number, say, 1000, when user navigates to unloaded data. All with no-script fallback links if you can't force user's to use JavaScript.
(Not sure how easy this is with C# frameworks; with Java's Wicket, this is quite easy.)
Paginate the records ! That will the the only solution (which you haven't yet tried by the way!). You could add Button controls to move between pages, and data loaded to a page when the page is loaded. Or the records could be loaded all at once and stored by the app, and just shown to the user when a page is shown.
Paging is definitely an answer to this. However - Do all your match inside SQL Stored Proc.. Instead of depending on the GridView default paging...
If you don't want to use Paging (some clients are very adamant to show all records) then you can use Scroll event to fetch records on the fly. If you using a Web Application, you can use Ajax Call to fetch next set of records by passing the pageNo,pagesize etc....

Categories

Resources