Update does not seems to be working with Select Parameter and DevExpress ASPxGridView

Posts   
 
    
amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 20-Jul-2010 13:12:22   

We have a gridView(DevExpress) and a llblDataSource with adapter and entity set into this.

We have specified a select query with session. The value in session is set to a non-existing value initially. For initial insert we are opening the grid in editable mode by writing Grid.AddNewRow().

This is working fine and we are able to insert the values in the database and we are getting correct events raised. In Inserted we are setting the session with the ID of newly inserted value. We get the single row correctly as expected.

Now when we try to update this, the events do not seem to be raised correctly and data is not being saved in database.

If we remove the select parameter update is working fine.

Maybe we are missing something very trivial.

Please find the sample that reproduces this attached. This is a website project so no project file is included. Please open existing site to open this.

LLBL Runtime Version: 3.0.10.611 OS: WinXP SP3 Visual Studio 2008 SP1 DevExpress 10.5 (Latest) LLBL Designer: July 2, 2010 Database: SQL Server 2005 (full)

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 20-Jul-2010 15:09:33   

Do you have another grid control (infragistics, MS etc) that you could try this against as well - We would like to eliminate DevExpress as the cause of the error.

Matt

amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 20-Jul-2010 19:15:19   

MTrinder wrote:

Do you have another grid control (infragistics, MS etc) that you could try this against as well - We would like to eliminate DevExpress as the cause of the error.

Matt

I do not have one currently. I think I forgot to mention this. When we set LivePersistance=false then we see this problem. With LivePersistance=true this problem does not happen. That should rule out DevExpress.

Amit Jindal

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 20-Jul-2010 21:49:55   

We will have a go at reproducing. Just a thought, when using LivePersistence=false, you need to handle the events raised by the DataSourceControl. See the documentation http://www.llblgen.com/documentation/3.0/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/Databinding%20at%20designtime%20and%20runtime/gencode_databinding_adapter_aspnet2x.htm#livepersistence

It appears from a quick look at your repro solution that you are not handling these events - could this be the cause of your issue...?

Matt

amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 21-Jul-2010 08:50:55   

MTrinder wrote:

We will have a go at reproducing. Just a thought, when using LivePersistence=false, you need to handle the events raised by the DataSourceControl. See the documentation http://www.llblgen.com/documentation/3.0/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/Databinding%20at%20designtime%20and%20runtime/gencode_databinding_adapter_aspnet2x.htm#livepersistence

It appears from a quick look at your repro solution that you are not handling these events - could this be the cause of your issue...?

Matt

Extremely SORRY. My mistake. Got confused with another problem we were having. We are NOT using LivePersistance=false. It is indeed LivePersistance=true. See the TestDataSourceSelectParameter.aspx.

Problem is when we specify a SelectParameter update is not working whereas insert is working. When we remove the select parameter it is working in both cases.

amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 21-Jul-2010 11:01:56   

We found the problem. When we set CacheLocation of LLBL DataSource to Session or ASPNetCache it is working. When we set to ViewState it is not working.

Any idea how we can address this (without changing all LLBL datasource instances)?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Jul-2010 11:29:50   

Similar issue was discussed here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12322

I think you will have to avoid The ViewState for the cacheLocation of the dataSoure control.

amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 27-Jul-2010 20:45:58   

Walaa wrote:

Similar issue was discussed here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12322

I think you will have to avoid The ViewState for the cacheLocation of the dataSoure control.

Dear Walaa, our project is quite large to simply use session at all places. The problem with using session (or cache) is that as we store values in session, something needs to clear them as well. Suppose a user is working on a page and we store the values in session, then as the user navigates to other pages, the values in session are still persisting. With time and multiple users this will consume a very large memory space.

As you have mentioned in ThreadID=12322 if the grid is not returning the correct viewstate as it is a AJAX control, there must be a way to enable the regular UpdatePanel behavior for the Grid/LLBL Source.

Also I am confused as to how it is working correctly with SQL data source. Perhaps because SQL DataSource is not persisting its values to ViewState or anything like that.

Alternately, DevExpress offers a ASPxHiddenField. Is there a way we can use ASPxHiddenField for persisting values with LLBL code? I can specify the hiddenfield in base/master page to make sure it is always there. I am hoping it is a AJAX control and works properly with Grid.

Finally, if you know of any way to disable the ASPxGridView's AJAX behavior so that it behaves and provides the correct complete ViewState?

Please help

Regards Amit Jindal

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-Jul-2010 21:54:09   

Don't ASP.NET sessions timeout by default after 20 minutes ? Although this is configurable. You should not experience "leaking" of resources by using sessions.

Matt

amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 28-Jul-2010 08:07:38   

MTrinder wrote:

Don't ASP.NET sessions timeout by default after 20 minutes ? Although this is configurable. You should not experience "leaking" of resources by using sessions.

Matt

Actually NO. It is a sliding timeout. So if I use my session (with no more than 19.9 minute interruptions) for 24 hours, it will last 24 hours 20 minutes.

http://msdn.microsoft.com/en-us/library/ms972429.aspx

**Timeout. **This option controls the length of time a session is considered valid. The session timeout is a sliding value; on each request the timeout period is set to the current time plus the timeout value

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Jul-2010 09:39:01   

What about ASPNetCache?

The following is quoted from the docs:

If the CacheLocation is set to ASPNetCache, the data is stored in the ASP.NET Cache using the following key:

__LLBLGENPRODATASOURCEDATA_Guid

where the Guid is a new Guid per LLBLGenProDataSource2 control instance. You can control the ASP.NET Cache duration as well. Use for that the LLBLGenProDataSource control property ASPNetCacheDuration which indicates in minutes the time the cached data should stay in the cache.

amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 28-Jul-2010 09:59:51   

Walaa wrote:

What about ASPNetCache?

The following is quoted from the docs:

If the CacheLocation is set to ASPNetCache, the data is stored in the ASP.NET Cache using the following key:

__LLBLGENPRODATASOURCEDATA_Guid

where the Guid is a new Guid per LLBLGenProDataSource2 control instance. You can control the ASP.NET Cache duration as well. Use for that the LLBLGenProDataSource control property ASPNetCacheDuration which indicates in minutes the time the cached data should stay in the cache.

I have explored that already. That is also less preferred as it is shared among all users and is more "valuable memory". We are using quite a lot of it for other non changing values (like Unit of measures or other cacheable things).

I would still like the Viewstate to work if possible.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 28-Jul-2010 10:34:08   

amitjindal wrote:

Walaa wrote:

Similar issue was discussed here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12322

I think you will have to avoid The ViewState for the cacheLocation of the dataSoure control.

Dear Walaa, our project is quite large to simply use session at all places. The problem with using session (or cache) is that as we store values in session, something needs to clear them as well. Suppose a user is working on a page and we store the values in session, then as the user navigates to other pages, the values in session are still persisting. With time and multiple users this will consume a very large memory space.

As you have mentioned in ThreadID=12322 if the grid is not returning the correct viewstate as it is a AJAX control, there must be a way to enable the regular UpdatePanel behavior for the Grid/LLBL Source.

Also I am confused as to how it is working correctly with SQL data source. Perhaps because SQL DataSource is not persisting its values to ViewState or anything like that.

sql datasource doesn't update existing objects it has read, it issues new commands. I.e. it doesn't need to keep existing objects around.

Entities which are fetched and which have to be edited ARE kept around, and this is a big difference and the reason why things go wrong with viewstate: the entities edited are stored in the viewstate, but the grid doesnt update those as the actions taken are on the client, not on the server.

Viewstate works OK as long as the grid does a postback when things change: if things change but there's no postback, what exactly is edited? -> not known.

Please understand that MS provided little information how to write a datasource control other than the simple docs they have in the MSDN. We did a lot of reverse engineering on their controls to see what should be done behind the scenes. Eventually we managed to make things work on a proper level.

With the AJAX enabled controls this changed a bit, as the get - post cycle was gone. In ASP.NET the whole page object with the controls is gone when the page is rendered. Postbacks happen in ajax land but not the way one would expect: the grid gets a call, the grid calls the datasource and that one simply does what it should do. However as you can see, when such a call comes in, there's no 'current' set of entities, as those are stored in the viewstate, but the postback from the grid directly isn't sending those.

The datasource just does what it is asked to do as a datasource is a slave control, it can't do things on its own. The problem with 'updates' is that you can only update things if the object to update is there. If that object isn't sent because it's in the viewstate and the call to the server isn't a full postback, there's no object to update for the datasourcecontrol and it gives up. How is it otherwise able to update things if these aren't there?

Alternately, DevExpress offers a ASPxHiddenField. Is there a way we can use ASPxHiddenField for persisting values with LLBL code? I can specify the hiddenfield in base/master page to make sure it is always there. I am hoping it is a AJAX control and works properly with Grid.

No that's not going to help, the entity collection edited is serialized into the page's viewstate, or stored in the session or stored in the asp.net cache if you want to. You picked the viewstate, that's not going to work as we described.

Finally, if you know of any way to disable the ASPxGridView's AJAX behavior so that it behaves and provides the correct complete ViewState?

I don't know, we're not experts on te ASPxGridView, sorry... did you ask DevExpress about this? Perhaps there's a setting where the complete viewstate of a page is send to the server on the ajax calls.

Frans Bouma | Lead developer LLBLGen Pro
amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 28-Jul-2010 10:51:50   

Otis wrote:

amitjindal wrote:

Walaa wrote:

Similar issue was discussed here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12322

I think you will have to avoid The ViewState for the cacheLocation of the dataSoure control.

Dear Walaa, our project is quite large to simply use session at all places. The problem with using session (or cache) is that as we store values in session, something needs to clear them as well. Suppose a user is working on a page and we store the values in session, then as the user navigates to other pages, the values in session are still persisting. With time and multiple users this will consume a very large memory space.

As you have mentioned in ThreadID=12322 if the grid is not returning the correct viewstate as it is a AJAX control, there must be a way to enable the regular UpdatePanel behavior for the Grid/LLBL Source.

Also I am confused as to how it is working correctly with SQL data source. Perhaps because SQL DataSource is not persisting its values to ViewState or anything like that.

sql datasource doesn't update existing objects it has read, it issues new commands. I.e. it doesn't need to keep existing objects around.

Entities which are fetched and which have to be edited ARE kept around, and this is a big difference and the reason why things go wrong with viewstate: the entities edited are stored in the viewstate, but the grid doesnt update those as the actions taken are on the client, not on the server.

Viewstate works OK as long as the grid does a postback when things change: if things change but there's no postback, what exactly is edited? -> not known.

Please understand that MS provided little information how to write a datasource control other than the simple docs they have in the MSDN. We did a lot of reverse engineering on their controls to see what should be done behind the scenes. Eventually we managed to make things work on a proper level.

With the AJAX enabled controls this changed a bit, as the get - post cycle was gone. In ASP.NET the whole page object with the controls is gone when the page is rendered. Postbacks happen in ajax land but not the way one would expect: the grid gets a call, the grid calls the datasource and that one simply does what it should do. However as you can see, when such a call comes in, there's no 'current' set of entities, as those are stored in the viewstate, but the postback from the grid directly isn't sending those.

The datasource just does what it is asked to do as a datasource is a slave control, it can't do things on its own. The problem with 'updates' is that you can only update things if the object to update is there. If that object isn't sent because it's in the viewstate and the call to the server isn't a full postback, there's no object to update for the datasourcecontrol and it gives up. How is it otherwise able to update things if these aren't there?

Alternately, DevExpress offers a ASPxHiddenField. Is there a way we can use ASPxHiddenField for persisting values with LLBL code? I can specify the hiddenfield in base/master page to make sure it is always there. I am hoping it is a AJAX control and works properly with Grid.

No that's not going to help, the entity collection edited is serialized into the page's viewstate, or stored in the session or stored in the asp.net cache if you want to. You picked the viewstate, that's not going to work as we described.

Finally, if you know of any way to disable the ASPxGridView's AJAX behavior so that it behaves and provides the correct complete ViewState?

I don't know, we're not experts on te ASPxGridView, sorry... did you ask DevExpress about this? Perhaps there's a setting where the complete viewstate of a page is send to the server on the ajax calls.

Dear Otis, I have opened a case with DevExpress as well. I am not sure if that is going to help as I am the intermediary and I do not have sufficient knowledge to explain them all the details. They have suggested to either disable the ViewState for datasources, or disable callbacks for the ASPxGridView.

I tried to look at the LLBL source code also, but it is difficult to figure out.

I am not aware of internals but I would expect that when a Grid changes, it should notify via some events. For example the ExecuteUpdate should have been called on IDataSource. If that is called, the datasource will get the new values. Now these new values need to be persisted back to ViewState. Now, as I understand since the Grid is ajax, you do get the call back but you have no way to persist the changed values into the viewstate.

Forgive me if I am asking a poor question, but will having the Grid and DataSource inside a Updatepanel help? Will then the update be able to persist back the values?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Jul-2010 17:28:17   

Forgive me if I am asking a poor question, but will having the Grid and DataSource inside a Updatepanel help? Will then the update be able to persist back the values?

I don't know, but you are mostly welcomed to try it simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 29-Jul-2010 11:26:22   

Looking at the help of ASPxGridView, there's a property called 'EnableCallBacks'. If you set it to false, the page is refreshed when you update (this disables ajax). Does that solve the problem? Your description about the problem in your last post is indeed what happens: there's nothing to update in the ajax based callback as the object to update isn't deserialized into an object first and then send back to the page again and updated into the viewstate...

Ajax based updates work only if the update is done without editing previous data or when the data is obtainable from a source other than the page, e.g. cache or session. So readonly data -> ajax is perfect. Updating data -> ajax isn't great unless you use session or cache.

Frans Bouma | Lead developer LLBLGen Pro