my question is very simple .
say , I have a grid or combo box , its databounded with a table in sql server database.
I wish when ever there occur some update in data table it refresh the grid .
I did it already with timer but doesn't it consuming resources by sending request after each time out ?
What are the possibilities in experts opinion to get this job done .
You are going to need to write some sort of Ajax type control that compares the TimeStamp of the last update when the grid loads to an Ajax or web service call that will return the TimeStamp of the last update/insert. If they are not the same, then refresh your grid. All web applications are stateless meaning that they do not retain state from call to call. Real time controls in some way shape or other do something similar in its behavior depending upon the arhcitecture the control is built on.
Related
I am using ASP.Net webform for my development and currently implement datatables.net. to perform some excel like data entry job. For more info, please go to http://datatables.net/release-datatables/extras/KeyTable/editing.html. I also added some add row and delete row functions at client side. Now I am stuck on how to push the entire table data to the server. It's look like excel and user can make the amendment. Whenever they plan to save the data, the user just need to click on save button and the entire table info shall be submitted to the server. For your information, no input textbox in this case because I am using keytable feature.
Please help!
Thanks.
I believe this datatables.net server side usage page has sServerMethod which may be fullfill your requirement. The data are passing in JSON format to server. In server side you can parse the JSON back to your DTO to update your data.
You can SqlBulkCopy for faster insertion of data in the database. You can search code for that on net.
You'll need to create an object collection of some kind in your handler to temporarily save the data into some kind of structure or object. What I did was append a row_id to the table row in the fnRowCallback of the Datatable, then grabbed it in the submitdata property of the Editable plugin, sending it to the server. Once there, I store it in an object, add it to the collection, and let editable update the table.
When you are ready to submit, fire it off, go to the handler, and send all of the data in the collection to the server as a mass update.
I have a gridview which contains 100 records i have set paging to 10. At page_load it fills the grid so the records are not going to change so i dont need to hit to database again.
There is a filter textbox availble at the top of 'Name' Column when user types some key it should filter the 100 records & should return the matched records (e.g using Contains filter).
It is not very difficult task if i user update panel. But, It takes time becoz i am fetching records on each key. Even i use viewstate it slows down the performance. Is there any alternative way to achieve this? I am wondering if u could use some javascript logic
If you are ok with implementing server side instead of with javascript, you could store the data in the cache object on first load, and then pull from cache on each subsequent hit.
A very simple example
Hi i have a sql database server runnin on my desktop. I want to create an asp.net application to detect when new data has been inserted into the database. Is there a command in visual studio to detect when theres new data right away?
Use the timestamp datatype on each column. This will stay identical until a change is made to any column in that row. If you combine this with the rowcount you can be certain if anything has changed in your database. You would need to cache the current timestamps and row count and compare them with the results of a query, you can then find out if there is a change.
So in your answer to:
Is there a command in visual studio to
detect when theres new data right
away?
Yes there is, although its not a command is the timestamp function (not to be confused with anything to do with the time)
Perhaps you need to provide more details to your scenario since constant querying of the database might not be the best way forward.
You can get a row count of your dataset and create a application
IN VB
Dim i as Integer
i=dataset.tables("table").rows.count
in sql backed return a count of a table and create a ASP.Net website to get the count and when count change alerts you
It may be heavier duty than you are looking for, but SQL Notification Services will do what you want. Essentially you execute a query and tell notification services you want to be notified whenever re-running that query would produce different results.
if you are using caching you can make it dependent on sql.
or you can fire email using sql trigger so when ever trigger get fired you will receive an email.
otherwise you will have to check your db again and again for any changes.
if you can provide more details about exact situation , we can provide more specific solution
You can create a webservice and call it using javascript.
here you can find sample how to call webservice using javascript:
function CallWebservice()
{
myWebService.isPrimeNumberWebService.callService(isPrimeNumberResult, "IsPrime",
testValue.value);
setTimeout("CallWebservice()",100);//here set time according to your requirement
}
For timer in javascript:
http://dotnetacademy.blogspot.com/2010/09/timer-in-javascript.html
For webservice in javaScript:
http://www.webreference.com/js/tips/020715.html
How to call webservice in JavaScript for FireFox 3.0
I have an asp.net page that calls a dll that will start a long process that updates product information. As the process is running, I want to provide the user with constant updates on which product that process is on and the status of the products. I've been having trouble getting this to work. I add information to a log text file and I was thinking that I'd redirect to a new page and have that page use Javascript to read from the text file every few seconds. My question is has anyone else tried this and does it work fairly well?
I would use Ajax and poll that text file for updates.
Make the long process so that it updates some state about the progress - status, last product processed, etc.
Once started, you might want to update the progress on only say every 50th item processed, to spare resources (you might not, it depends on what you want) on the ASP.NET side.
If the processing is associated with the current session, you might want to put the state in the session. If it is not - e.g. global - put it in some global state.
Then poll the state once in a while through Ajax from javascript, using e.g. JSON and update the UI accordingly.
Make sure you use proper locking when accessing the shared state.
Also, try to keep the state small (store only what is absolutely required to get the data for the js gui).
Rather than outputting the status to a text based log file (or, in addition to using the log file; you can use both), you could output the status to a Database table. For example, structure the table as so:
Queue:
id (Primary Key)
user_id (Foreign Key)
product_id (Foreign Key) //if available
batch_size //total set of products in the batch this message was generated from
batch_remaining //number remaining in this batch
message
So now you have a queue. Now when a user goes on a particular page, you can do one of two things:
Grab some relevant data from the Queue and display it in the header. This will be updated every time the page is refreshed.
Create an AJAX handler that will poll a web service to grab the data at intervals. This way you can have the status update every 15 or 20 seconds, even if the user is on the same page without refreshing.
You can delete the rows from the Queue after they've been sent, or if you want to retain that data, add another column called sent and set it to true once the user has seen that data.
I have a page that contains a Gridview showing a record from a db table e.g. "tblEmployee".
If a record is inserted/updated/deleted in that table then I need my page to be reloaded so that the gridview will show the updated records. Records may be inserted/updated/deleted from any other application.
To rebind the gridview I have to reload the page. Suppose I open the page in my browser and no postback is done. After 10 minutes a record is inserted into the table by some other apps. How can I reload the page automatically, not manually by clicking refresh button when the records in db table changed? I am using Sql server 2005 as DB and ASP.Net 3.5(C#)
Please suggest how to implement this.
Thanks.
Here's two approaches... one using a trigger, the other using SqlDependency. I would recommend using SqlDependency, but I'm outlining another approach because you indicated trouble with SqlDependency.
Create a table with columns for table name and last update date. Create a trigger on tblEmployee to update that table on any insert/update/delete.
When the page is loaded, you'll want to store the current last update date for the table. Depending on how your page is setup, you could store it in ViewState or as a hidden field on the page. Then you'll need to poll for changes. There are many ways to do this. You could write a simple Page Method that returns the last update date, call it from JavaScript, and compare it to the date you stored in the hidden field. Or you could use an UpdatePanel with a Timer control and compare to the value you stored in ViewState.
Now this approach hits the database more than necessary. If that's a problem, use SqlDependency with SQL 2005 or greater. Create a SqlDependency and insert the current date into the Cache with this dependency object. Poll this cache item from the page as described above. When the dependency changes (OnChange event), update the cache item date again.
I see not other option that having a polling mechanism, i.e. using setTimeout+jQuery or ASP.NET AJAX Timer that pulls the information at intervals.
Basically what you want is for the server to notify the client that an update has occurred and in a web/ASP.NET application communication is always initiated by the client. So polling is your only option.
You could use the SqlDependency class:
Here's a getting started example: SqlDependency in an ASP.NET Application (ADO.NET)