简体   繁体   中英

How to fill the gap between server-side and client-side in ASP.NET webforms?

Folks,

I want to know how to fill the gap between the server-side and client-side in ASP.NET webforms, How can I trigger something in Client-side from Server-Side and vise verse? How can I open jQuery UI dialog from server-side? How can I obtain the modal dialog with the postback like for example if I have a paged GridView inside jQuery UI modal dialog and when user change page it close. I need to know what is the best to fill this gap?

Asp.net default solution is to use update panels . This will create ajax requests and send them to the server. (Takes care of your paging problem.)

To open dialogs on events happening on the server:

Http is connectionless by default, you will not be able to do this in asp.net out of the box.

You can look at methods like comet . This can be done in asp.net using async calls.

There are a few comet samples using asp.net available on the net. But it may involve significant changes to your code. There are also a few libraries like Signar that may help.

When it comes to the server interacting with the client in a web environment, there are pretty solid limitations you have to work with. I'm going to be generic in my answer here.

When you want to pass something from the client to the server, that's normally easy to do. One relatively common way to do that is through AJAX. ASP.NET WebForms, in its barest, communicates through a <form> submit.

Doing the inverse (ie server initiating a message to the client), that's a more difficult use case. HTTP, just from the way it's implemented, makes for easy client -> server stuff, but server -> client is nearly impossible. It just wasn't designed for that. The server can't send the client something without the client first asking for it. And that's the big problem: how will the client know when the server needs to send it something? Kind of defeats the purpose.

Granted, there is a handful of stuff that's currently in use to bridge that. One of the more promising is web sockets , which is a solid, concrete way to allow the server to push messages to the client without the client asking for it (do note that IIS 7 out-of-the-box can't support web sockets AFAIK). Another is Comet, or even AJAX through periodic polling.

A good wrapper for the functionality you seem to want is SignalR . I've been using it for a while, and it seems to be working really well so far. It uses web sockets when it's available, and uses fallbacks silently when it's not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM