0

In ASP.NET 4.5 C# web forms application, I would like to avoid postback on a button click event which pulls data from database and binds the gridview. The gridview is going to have an edit button on each row. I would like to avoid postback when that edit button is clicked. There's also going to be a button on each row which will show a modal pop-up when clicked and this pop-up is going to have buttons. When the modal pop-up is closed, data in that gridview row will be updated.

I have been using updatepanels. They do avoid full-page refresh, but don't reduce viewstate. The gridview is going to return a lot of rows. So when I click on any of the buttons in gridview, it's going to take a while for even the gridview to go into edit mode or for the pop-up to show up and. How would I reduce or eliminate this time lag? Thank you.

engg
  • 343
  • 1
  • 4
  • 12
  • 1
    Your question is not a good format for SO. You're trying to ask too much at once, and you're also asking us to recommend software. Questions asking us to recommend software aren't allowed. As for your main question, I'd suggest not using a GridView or UpdatePanels for this. Instead, disable ViewState, then use a repeater to create an HTML table. Inside your table use buttons that run local JavaScript, and use AJAX if you need to communicate with your server. – mason Oct 20 '14 at 14:05
  • Thanks mason, I will check it out. If someone has used software for the same purpose and liked it, I would like to know. Yes, it's not the main question. – engg Oct 20 '14 at 14:50
  • 1
    Yes, many people use the repeater technique when they used finer grained control over the generated HTML. [Most people](http://stackoverflow.com/questions/113479/when-to-enable-disable-viewstate) (and Microsoft) now recommend disabling ViewState and only selectively enabling it when you need it anyways. – mason Oct 20 '14 at 14:52
  • Thanks. Yes, I am going to disable viewstate for the page and selectively enable. The problem is if I don't get the Ajax working for table (gridview/repeater) bind and edit buttons, it will need a postback and will have to enable viewstate for most controls and it will be very slow due to the large no. of rows in the table. – engg Oct 20 '14 at 15:24
  • 1
    Well, you *can* get AJAX working. It's a very common technique. No, you don't need ViewState. If you needed to store data on the client to be used for future requests, then HTML 5 has [web storage](http://en.wikipedia.org/wiki/Web_storage). – mason Oct 20 '14 at 15:27
  • Thanks. Just mentioned modal pop-up in the question, need to see if repeater will work for all these cases. – engg Oct 20 '14 at 17:34
  • You need to fix your question by removing stuff (and possibly opening new questions each with limited scope), not by adding more to it. – MatthewMartin Oct 20 '14 at 17:54
  • I have removed stuff from the question. Please let me know if it needs further work. Thank you. – engg Oct 20 '14 at 19:56
  • @engg It needs further work, because now it's unclear what you're asking. – mason Oct 20 '14 at 20:42

1 Answers1

3

A comment-

SPA (single page apps that don't post or post back) and WebForms mix poorly.

  1. You won't be able to take advantage of most of the features of 3rd party libraries, which for me was the main benefit of WebForms-- being able to get so much functionality right away.
  2. You can disable postbacks by throwing an exception on each postback. (Test for IsPostBack)
  3. MS-Ajax is craptastic. I tried to use it, I regretted it. Many 3rd party WebForm libraries are tied to it. Even MS has recognized that MS-Ajax is a failed product and isn't pushing it forward anymore.
  4. If you pick a SPA library, pick one, e.g. Angular or JQuery or whatever. When you put both on the page, they fight for control of the DOM.
  5. WebForms isn't even a good template language. A good templating language does cause non-stop misery when you need to deal with client Ids. In WebForms easier to generate all the templates on a single page and show and hide the parts than it is to get sections to generate dynamically, which makes sense because WebForms is a server side templating language-- this can make for a huge page. You can sort of use MS-Ajax, but that calls back to the server to get more template markup when that step could have been skipped by doing the templating client side.
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
  • Thanks MatthewMartin. It's too late for me now to shun webforms and switch to MVC or something. – engg Oct 20 '14 at 17:29
  • 1
    @engg All of this was good advice. No, it's not too late to switch to MVC (or at least drop MS-AJAX in favor of jQuery UI or similar). If you stick with bad technology, it will cost you more in the long run. Can you be effective with Web Forms? Sure. But I've found that the more effective techniques lean in the direction of using MVC/[Web Pages](http://www.asp.net/web-pages) anyways (ex: Repeater instead of GridView, well you might as well use a Razor `foreach` loop). – mason Oct 20 '14 at 18:08
  • I am looking into MVC. How's the learning curve to switch from webforms to MVC? – engg Oct 21 '14 at 13:46
  • 1
    WebForms was easy if you were a VB6 developer. MVC isn't especially difficut, but few concept from WebForms apply to MVC-- it's like a whole new thing. Also MVC patterns seem to be more JavaScript friendly (where WebForms seemed to actively fight against using javascript). You can do hybrid (aspx pages in a MVC project)... lemme look up the link : here-> https://www.packtpub.com/books/content/mixing-aspnet-webforms-and-aspnet-mvc That allows you to do some pages as aspx and the main app as mvc. – MatthewMartin Oct 21 '14 at 14:10
  • I am getting more and more excited about MVC as I am reading more about it. I am just concerned about the seemingly steep learning curve it has as it's a time-sensitive project. @mason mentioned 'web pages'. Is that a good alternative (to web forms) too for what I am trying to do? Thanks. – engg Oct 21 '14 at 18:05
  • 1
    @engg I would say that it's much easier to learn MVC than Web Forms. Primarily because you're using actual HTML and learning how to properly implement the client side. And that's coming from a guy that has used Web Forms longer (and first). Web Pages uses Razor, the default view engine for MVC. So it's very similar to MVC. But if you need database stuff and routing, then go with MVC. The best way to learn is to jump right in and do it. Check out videos from TechEd or Build 2014. Watch MS devs do some examples with MVC and you'll see how simple it is. – mason Oct 21 '14 at 18:09