Repopulate Dropdown when database changes in asp.net mvc - asp.net

Customer table has two fields : FullName And Gender
Lets say , I have dropdown customers. Customers is populated by fetching data from the customer table.
Now Lets I say I have two tabs open in the browser
1)You can perform CRUD functions on Customer table
2)Contains the customers dropdown and some other relevant data.
Performing a Crud operation in tab1 should automatically update the dropdown in the second tab without a refresh page.
How can I achieve this in asp.net mvc or asp.net ?
Like is it possible to bind my dropdown to a table change in asp.net ?

You need to make use of Web Sockets. This protocol keeps a TCP connection open between the server and the client and changes to the customer table can be sent to the client.
The good news is that Microsoft provides an implementation of Web Socket protocol called SignalR and that simplifies things a lot.

Related

Real-time updates ASP.NET using Entity Framework

I am trying to make a proof of concept where a simple ASP.NET web application that is using Entity framework updates automatically when a record is added to my Azure SQL Database. I did some research and stumbled across SignalR and SqlDependency. At first sight this seems exactly what I want but according to this:
Creating a Query for Notification
There are a lot of restrictions if I want to use SqlDependency. Like I can't do something like this:
context.table.Take(100).Skip(50).ToList();
Because this would result in a SELECT TOP and that is not permitted according to the previous link. I also don't want to get the whole table because that would be over 100 000 records and that would cause performance issues.
Is there a way to have real time data (only like the last 20 inserted records) from my azure SQL database shown on my ASP.NET web application? Preferably not with a periodic refresh but only if a record is inserted.

asp.net refresh web page on DB changes

I'm currently working on an asp.net website.
I have a page (main.aspx) which displays records from a database table. Another page (editing.aspx) is responsible for editing records in the DB table.
let's assume we have a scenario where two users are using the website, user1 (on session1) is viewing the records in main.aspx, user2 (on session2) is editing the DB table from editing.aspx, what I want is: to refresh main.aspx for user1 when user2 saves his changes to the DB table.
I tried using an AJAX timer that pulls the DB for changes every 10 seconds, and refreshes an UpdatePanel (in which I'm displaying the records), and it works just fine, but I want to know if there'se a better way than pulling the DB server for changes.
thanks.
It is debatable if the other way is better but what you are looking for is persistent connection to the server that lets the server send e message to the page. There is a good library for .NET called SignalR that abstracts away the details. It is certainly more network efficient but depending on your use case the update panel may be good enough. Basically with SignalR you will send a message from the server-side code of your edit page which would be received by a JavaScript function on your main page. Then you either show the data or cause a refresh in some way.

How to trigger a local application from a SQL server or web server

We have created a ASP.NET website to give ticket-based support to our customers. Together with our software, we have given a separate VB6 application where customers can send queries to us, and they can see replies, if any. This application loads the ASP.NET page inside a Web Browser control. When customers send queries, it will be added to our database; and we send replies to their questions. So ultimately we will be putting replies in a "reply" column of the table.
I want to show replies to customers as soon as we add them. We have set a timer in our support application which checks whether a reply is present in the database. If so, then we show it. We need to check every 5 minutes that any replies are present in the database. So I think it is what is responsible for more traffic and load on my web server and SQL Server.
Is there any mechanism by which we can trigger the support application which loads the ASP page from the web server? whenever we add a reply to a particular customer, it should be shown to that customer. How this can be done? Are there any better ideas?

is sql transaction can apply in web application

Can I use sql transactions in web applications?
I.e. when a user starts filling forms the transaction begins. But when another user fills the form at the same time does he get another transaction?
The form is complete when three pages of data are submitted by the user. The data are saved to different tables after filling the specific pages; after completing all form pages the commit should be invoked.
Does this work for a web application where there may be multiple users at same time filling in forms?
I used this method but I get errors that the database/server is not responding/busy.
Is there is any other option to avoid incomplete form submission?
Using a transaction on a forum application is not going to be a good idea, if 2 users are trying to submit new threads at around the same, User 2 would be blocked from accessing/updating tables with the data they are submitting until User 1's transaction is committed.

How much data can/should you store in a users session object?

We have several wizard style form applications on our website where we capture information from the user on each page and then submit to a backend process using a web service.
Unfortunately we can't submit the information in chunks during each form submission so we have to store it the users session until the end of the process and submit it all at the same time.
Is the amount of server memory/sql server disk space the only constraint on how much I can store in users sessions or is there something else I need to consider?
Edit: The site is built on ASP.NET web forms.
Assuming the information is not sensitive then you could store the information in a cookie which would reduce the amount of information required to be stored server side. This would also allow you to access the information via JavaScript.
Alternatively you could use the viewstate to store the information although this can lead to large amounts of data being sent between the server and the client and not my preferred solution.
The amount of session information you should store varies wildly depending on the application, number of expected users, server specification etc. To give a more accurate answer would require more information :)
Finally, assuming that the information collected throughout the process is not required from page to page then you could store all the information in a database table and only store the records unique id in the session. As each page is submitted the db record is updated and then on the final page all the information is retrieved and submitted. This is not an idea solution if you need to retrieve previous information on each subsequent page due to the number of db reads required.
You could also have 1 asp page with the entire html form, and hide parts of it until the user fill and "submits" the visible part...
then simply hide the part that is filled out and show the next part of the form...
This would be extremely easy in the .NET framework, use panels for each "wizard step" and add loggic when to display and hide each panel.
you will then have all the data on one page.
If you use a traditional HTTP model (i.e. don't use runat="server") you can post the data to another asp page and place the posted data into hidden form elements, you can do this for however many pages you need thus avoiding placing anything in a session variable.
Since it is problematic from performance point of view to store large amounts of data in user Session object, ASP.Net provides some other workarounds on top of what is mentioned in the posts above. ASP.NET Profile Provider allows you to persist session related information in a database. You can also use Session State Server which uses a separate server to store all Session information. Both of these situations take into account if you need to use clusters or load balancers, the servers can still recognize the session information across different servers. If you store information in the Http Session object, you run into the problem that one user must always go to the same server for that session.
Session, viewstate, database. These are all slow but will get the job done.
Hidden form fields is the answer I like best.
There are other ways to persist state. Cookies, popup window, frameset or iframes.

Resources