My scenario:
After client login, my user will be redirected to the index.aspx page.
Inside this page I will put one div with a gridview inside.
This gridview will be showing data from one table.
My question is: How to refresh this gridview always that one record is
saved on this table?
Ps.: I´ve seen a lot of examples using "server push" tecnology, comet, ajax, etc.
Don´t know the best way to do that and can´t find a really simple example.
When a new record is added to the table, the real challenge is communicating those changes to the client in real-time without polling in intervals or requiring some sort of user interaction.
You have a couple of options:
Your best bet is to use a WebSocket, which enables bidirectional communication between the client and server. This is the solution I would pick.
Here are some examples using WebSockets:
Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
HTML5 C# WebSockets Server and ASP.NET Client Implementation
C# WebSocket Server
WebSockets in ASP.NET 4.5
WebHooks and WebSockets in ASP.NET
There are a few good libraries around too that will take care of most of the leg work. A couple to check out are WebSync and PokeIn. Both products offer decent documentation and community editions that you can download for free.
Here are some tutorials to check out:
WebSync Tutorials
PokeIn Basic Tutorial / PokeIn Advanced Tutorial
Use AJAX to poll for changes every X number of seconds. If changes are detected reload the page, otherwise do nothing.
You can use setinterval javascript method. I act as a timer and use submit form to refresh the page. other method could be asp.net ajax toolkit timer control here
put your grid inside an update panel and set "Update Mode" to always
You can use Update Panel which uses AJAX under the hood. Refer to this link for a short and simple demo.
You can also use plain old html
<META HTTP-EQUIV="REFRESH"
CONTENT="15;URL=http://www.I18nGuy.com/index.html">
Related
I'm developing a website in C# MVC including WEB API. When an API URL in my project is called from an external system, I want to show a message (not a push message, only show a text in a div) in one of my view that the API function is executing.Is this possible?
First Of All its possible yes,
you need To use SignalR To notify the Views:
YouTube totrual Here
Github : Here
Then You use the Signal R to push a Notification when a cross origin request happen
using action filters
the signalR subscribers can be view pages using Jquery.
SignalR on Client
full exmaple :here
Yes it is posssible. One (pretty easy) way is to use the awesome SignalR or SignalR core framework. Check this for differences. Real-time web functionality enables server-side code to push content to clients instantly.
Basically you will create a Hub on the server that clients connect to. In your WebApi method, you can then call the client method. Then in the client you will use javascript to respond to the server call and then you will set the div content from this method.
See the docs.
Hope it helps!
I think Signal R is best choise too. But maybe you want to another alternative. You can look at Node Js.
Node js.org
General Tutorial
General Tutorial 2
For .NET Tutorial
I have this requirement for my project. Already there is an existing windows form application,
Which sends email when a button is clicked. There's a lot of code behind the application.
It validates the field serial number which is a text box by connecting to database.
The validation error pops up as another windows form.
It generates a report form after sending an email. There's a configuration button which is accessible only to particular users which opens configuration form which has details of email settings.
Now All this is developed using windows forms. My new requirement is i need to develop
the same in a ASP.NET web page having similar functionality.
I tried using click once deployment, but that's not they needed. they want it as a webpage.
Is there any tool or way i can show the application in ASP.NET web page?
Do i need to start the coding from scratch?
Thanks in advance
As to what Rex said, you are going to have to start from scratch. The coding behind it is different. Validation and functions work differently in asp.net than they do in .net.
You will have to start from scratch for reasons already mentioned. If this is your first ASP.net application here are a few tips for what you want to do:
1- For validation and transfer to the email report to work in a similar way you can use Response.Redirect or Server.Transfer or JavaScript. All of those methods have pros and cons, see Server.Transfer Vs. Response.Redirect for an example of the first two. For javascript you'll need to write a javascript function in the .aspx file or inject javascript in the page with response.write.
2- If you validate with JavaScript you also need to validate server side to make sure someone doesn't try to pass bad values to you. JavaScript can be disabled and users can call your report page and configuration page directly, while with windows forms you control that flow you don't on webpages.
3- You'll probably have to use CSS to style elements in your email configuration form and in your initial form. Positioning, docking, anchoring and so on is completely different in webpage and done with CSS. Have fun learning the CSS boxing model, what absolute positioning is, and what clear and float do ;)
4- The most important thing is that the Web is stateless. You can't use private members to keep information between page reload on the web. When you pass a value between 2 pages the first one doesn't exist anymore so you can't just do Class.somemembervariable as usual. Check out what viewstate, sessionstate and querystring are. When your page reload, without these, everything is loss. Clicking a server-side button cause the page to reload, which you need to handle (it's called postback). This also implies that when you serve the report page you will have to pass some Id for the email and check the user, so when you call the 2nd page you need to pass to it some id so it can work. I spent more time on this one because it's the most important difference between asp.net and windows form.
5- For restricting access to your email settings page you will probably need to use windows authentification if this is an Intranet site or Forms authentification if this is an Internet site. Check Starting ASP.NET Forms Authentication for some basic overview.
6- ASP.Net has a codebehind file where you write the actual code, and an .aspx page where you put the html tags, javascript, styles, and data binding with <%= %> tags.
7- You will probably have to work with IIS as well to make your website work unless you work at a very formal place where specific peoples take care of that. At the very basic you'll have to create an application pool, make it compatible with 32/64 bits and set up authentification in IIS.
I want to include the Sharepoint people picker control type in my application, My app is developed in asp.net MVC. is there a way so that i can include the GAL feature in my asp.net application. This should work even if the outlook is not installed in user pc.
Taken from this page dated March 1 2013
"SP controls can only be used on SP hosted pages. Currently the only control designed from the ground up to be consumed on all page types (provider-hosted, auto-hosted or sp hosted) is the chrome control."
and another post from an MSFT
"I've consulted with several colleagues and the consensus seems to be that SharePoint's client side people picker, which is JavaScript, cannot be used in a provider-hosted app. The reason is that there's no way to get a client context on a remote web page. You mention the TokenHelper.cs which is managed code, not JavaScript. I have a question pending with the product team to see if there's anyway to get the context with managed code and pass it to JavaScript. I didn't want you to have to wait any longer for an answer."
I would suggest writing a plugin. (Although I have never had the requirement to implement it YET)
How :
you write a controller that loads users from AD, and then send a JSON object of these to your client via AJAX and then use jquery auto complete to filter names as the user types.
Or
Simulate the "check User " button by making AJAX calls to that controller and check if name exist on click of that button. then write appropriate error messages if false.
I would still be on the lookout for other solutions though
I am working on a project in which one functionality is that this page obtains data from other page (not web service) and then displays it on a grid and use hightcharts for charting.
The problem is that this data I want to read is in anotherpage.
I know that I can read html from other pages... but to get this information on the page, I need to fill 2 input text for a filter and press a submit button.. then it displays a table and this is the table where I need to extract the information.
Is there a way to do this automatically on c#?
There are plenty of ways to do this; the most common revolve around AJAX. You can initiate a callback from the client via Javascript to a method on the server, which can update controls in an UpdatePanel, for example.
You can also make client side calls to server side Page Methods. Effectively, this is a static method on your webform that you can call from the client via javascript/jquery and AJAX.
EDIT.
It turns out that you want to scrape another site. The easiest way for you to do this is have a server side page method on your website that does this - it requests the page from the client site, extracts the info you want, and then returns that to your client. Your client can of course call this as a page method.
See https://web.archive.org/web/20210513000146/http://www.4guysfromrolla.com/webtech/070601-1.shtml for a tutorial, and I do suggest using the HTML Agility Pack as that article mentions.
Further EDIT
You want to further manipulate the page on the remote site; if you can't or don't want to speak to the developers of that site to work out a way of doing it programmatically, then you'll have to cheat. Get Firebug and Tamper Data. Use Firebug and Tamper Data to see how clicking the button on the remote site makes a request and posts it to the server - you want to emulate doing the same. If you know what data is being posted then you can, from your server, make exactly the same post.
You often have this kind of problem when trying to scrape AJAX websites.
I know the question sounds too vague so let me explain exactly what I want to implement.
I have a WebApplication that many users log into to submit a request, Request in my project is a form that accepts some information from the user and when he click submit, it reflects on the administrator page. then the admin can grant or decline this request. and of course the result need to be sent to the user's 'Pending Requests' page.
this process is all about time so I need a clean and efficient way to show the admin the requests instantly and for the user to see the admin's response instantly. (kind of like facebook notification system).
I hope my problem is know clear. I understand that there are many ways to implement this and I have a very small knowledge about them. But I just want you guys to recommend an effecient way because I'm sure that the good ways to do this is limited.
Thanks in advance everybody :)
I will suggest you take a look at SignalR (https://github.com/SignalR/SignalR). It is a framework developed by a few MS developers for doing long polling/notifications from the server.
Link for webforms walkthrough - http://www.infinitelooping.com/blog/2011/10/17/using-signalr/.
You could also look into using a Timer control. It's a client side control that will cause a postback for ASP.NET AJAX applications. Here's a simple tutorial
http://ajax.net-tutorials.com/controls/timer-control/
What you're talking about is a 'push' notification, where the server would pass a notification to the client (a browser) without the client requesting anything.
This isnt something which HTTP is naturally capable of, however have a read about Comet - this will let you know the current state of what is possible.
You may opt for creating a 'heartbeat' on the client side - a polling mechanism which requests from the server every x seconds, and updates the page when new content is found.
I need a clean and efficient way to show the admin the requests instantly and for the user to see the admin's response instantly.
Instantly is a very strong term and isn't usually very scalable.
For some ideas on how you might implement this I'd recommend you take a look at Wikipedia's Comet Programming page
When a user submit requests I assume that his request is first stored in the database. So on the admin & user part you use ajax which periodically update data from database (for un-approved data), do some google search on ajax auto-update or Javascript's timeout or similar function. The same process will be involved in user part.