Software-Entwicklung, Projektleitung, Web-Design
Kontakt:   +41 61 927 18 30
You are here:

Blog

Ajax cannot kill you, but sometimes it tries...

by Joerg Lang | Jan 07, 2011

Well it is really true. Using Ajax is cool and definitely a must when you design a new ASP.NET site. But sometimes it leads to programming phenomenons that are hard to track down.

Today I was working on a project where I have to use the standard components that come with ASP.NET and the AJAX toolkit. I had a GridView to update and delete a few values from a XML file. Using the built in commands from the GridView it was easy to add the update and delete features. However the GridView does not have a built in Insert feature. So I added a panel with the fields that need to be inserted, added some RequiredValidator controls and used the ModalPopupExtender from the AJAX toolkit to show the insert form, when the user clicks on a "Add new row" link above the grid.

Actually quite easy and also quite a nice interface for inserting new rows to the table.

But then the problem begun...

When I retested the form, I was able to add new rows, delete existing rows, but the update feature did not work anymore. The GridView switched to edit mode, but when clicking on the Update link nothing happened. The Cancel link however worked, but the RowUpdating event did not fire anymore. Nothing, zero, nada, zip, dead silence. I thought that must be a known problem and I will find a solution on the internet quickly. But no, nothing that really described my situation.

Have you found the problem, following the descriptions what I did? No? What if I told you that it is quite obvious?
Well the problem were the validation controls on the hidden AJAX panel. When the Update link tried to post back the changed values from the grid, the hidden validation controls on the hidden AJAX panel kicked in. The values for the two fields I had on the form were empty, so the postback never occurred.

So as you can see, AJAX (the great warrior) really tries to kill you sometimes.

The solution to the problem is quite easy. Either the grid should not cause validation on postback, or the hidden fields must not be empty. I opted for the second solution. When the GridView switches to edit view, I put some dummy values into the fields and after the update is finished I clear the fields again. After having implemented these few lines of code, the form was working again as expected.

Hope this description might help you in a similar situation when a event does not fire in an AJAX scenario.

3 Comments

  1. 3 Hollie 25 Dez
    Just cause it's simple doesn't mean it's not super hlpeful.
  2. 2 Earnest 14 Mrz
    I was excited to find this page. I want to to thank you for ones time just for this wonderful read!! I definitely loved every little bit of it and i also have you saved to fav to see new information on your blog.
  3. 1 Pharme184 12 Dez
    Hello! bdaeeeg interesting bdaeeeg site! I'm really like it! Very, very bdaeeeg good!

Comment

  1. RadEditor - HTML WYSIWYG Editor. MS Word-like content editing experience thanks to a rich set of formatting tools, dropdowns, dialogs, system modules and built-in spell-check.
    RadEditor's components - toolbar, content area, modes and modules
       
    Toolbar's wrapper 
     
    Content area wrapper
    RadEditor's bottom area: Design, Html and Preview modes, Statistics module and resize handle.
    It contains RadEditor's Modes/views (HTML, Design and Preview), Statistics and Resizer
    Editor Mode buttonsStatistics moduleEditor resizer
      
    RadEditor's Modules - special tools used to provide extra information such as Tag Inspector, Real Time HTML Viewer, Tag Properties and other.