HowTo stop PerformSelect operations on postback?

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 20-Sep-2006 21:33:45   

In a web user control, I have 2 combo boxes, 2 data source controls, and a link button. One combo is for a list of countries, the other is for a list of regions. One data source control is for countries, one is for regions.

Both data sources have live persistence == false and both data container types are entity collection.

The regions data source has a select parameter that points to the selected value of the country combo.

All data binding to this point works great. I select a country, a list of regions for the country is placed into the regions drop down.

I have PerformSelect operations that are being executed as they should, except for when I click the link button. When a user clicks the link button, the PerformSelect method is fired for the regions data source and the previously selected state is reset. How can I stop this?

When the user control loads for the first time, PerformSelect is fired for both data source controls. When a user selects an item in the country combo the PerformSelect is fired for the regions data source and the regions combo is updated. These are to be expected but I wouldnt expect any PerformSelect operations to execute when clicking a link button.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 22:09:44   

Try enableviewstate = true again, as the selectparameter is the one that prevented it from working.

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 20-Sep-2006 23:06:58   

I will double check but I beleive that EnableViewState == true for both data sources and both combos.

I do know, that I am not explicitly setting the value of the select parameter in code. (This is just a guess, but) Do I need to explicitly set the value of the SelectParameter for the RegionsDataSource in order for the SelectParameter Value to be set in viewstate?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Sep-2006 09:26:28   

When you click on the button, the PerformSelect method is fired for the regions data source only, and preformSelect is not fired for the countries?

Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 21-Sep-2006 16:05:40   

Walaa wrote:

When you click on the button, the PerformSelect method is fired for the regions data source only, and preformSelect is not fired for the countries?

Yes this is correct.

View state is enabled on all UI controls and datasource controls contained within the user control.

I can send you a copy of the user control and codebehind if you like.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Sep-2006 17:08:00   

It's odd though. The datasourcecontrol simply gets a request to read data, from the combobox control, and it then checks if the data read already is good enough. It does this based on a test whether the page is still the same, sorter is still the same, and for example if Refetch is true or not.

Do you set something on the datasourcecontrol in the page load handler?

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 21-Sep-2006 20:10:18   

There is no code in the PageLoad handler. Here is the only code in the web user control that ineracts with the data source controls.


    protected void CountryDataSource_PerformSelect(object sender, PerformSelectEventArgs2 e)
    {
        LoadCountries(e);
    }
    protected void StateDataSource_PerformSelect(object sender, PerformSelectEventArgs2 e)
    {
        LoadStates(e);
    }

    private void LoadCountries(PerformSelectEventArgs2 e)
    {
        EntityCollectionNonGeneric countryData = (EntityCollectionNonGeneric)e.ContainedCollection;
        MyCountryRegionEntity.FetchAllCountries(ref countryData);
    }
    private void LoadStates(PerformSelectEventArgs2 e)
    {
        if (CountryCombo.SelectedItem != null &&
                    string.IsNullOrEmpty(CountryCombo.SelectedValue) == false)
        {
            EntityCollectionNonGeneric stateData = (EntityCollectionNonGeneric)e.ContainedCollection;
            MyStateProvinceEntity.FetchStatesByRegion(ref stateData,
                CountryCombo.SelectedValue);
        }
    }
    protected void CountryCombo_DataBound(object sender, EventArgs e)
    {
        CountryCombo.Items.Insert(0, "");
        CountryCombo.SelectedIndex = 0;
    }

This is the html definition of the datasource controls:


            <llblgenpro:LLBLGenProDataSource2 ID="CountryDataSource" runat="server" AdapterTypeName="Fadv.Samples.BusinessLib.DatabaseSpecific.DataAccessAdapter, Fadv.Samples.BusinessLibDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="Fadv.Samples.BusinessLib.FactoryClasses.CountryRegionEntityFactory, Fadv.Samples.BusinessLib" OnPerformSelect="CountryDataSource_PerformSelect" LivePersistence="False">
            </llblgenpro:LLBLGenProDataSource2>
            <llblgenpro:LLBLGenProDataSource2 ID="StateDataSource" runat="server" AdapterTypeName="Fadv.Samples.BusinessLib.DatabaseSpecific.DataAccessAdapter, Fadv.Samples.BusinessLibDBSpecific" DataContainerType="EntityCollection" EntityFactoryTypeName="Fadv.Samples.BusinessLib.FactoryClasses.StateProvinceEntityFactory, Fadv.Samples.BusinessLib" OnPerformSelect="StateDataSource_PerformSelect" LivePersistence="False">
                <SelectParameters>
                    <asp:ControlParameter ControlID="CountryCombo" Name="CountryCode" PropertyName="SelectedValue" Type="String" ConvertEmptyStringToNull="False" DefaultValue="&quot;&quot;" />
                </SelectParameters>
            </llblgenpro:LLBLGenProDataSource2>

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 13:03:11   

I can also reproduce it when I have two comboboxes on a form, each combobox is bound to a datasourcecontrol (their own), and I have both comboboxes set to autopostback, and the second is filtered by the first (Categories and products). When I select a product (the second combobox), it always selects data and thus reverts to the first one. Very strange. It seems Refetch is true. Odd.

(edit) seems to be the linked selectparameter. If I remove that, it doesn't select again as refetch isn't true. Looking into it.

(edit) ARG!!! Why do these Microsoft devvers put their energy in Atlas while their current stuff is so broken... rage . The control's event handler which is bound to selectparameters.ParametersChanged is called, and thus refetch is true.

How come the parameters are changed when they're the same. Now I've to check if this 'changed' is not just 'changed' but simply 'they're set again because of a postback!'...

Perhaps I'm using it wrong, but because there's NO (that's 0.0, zip nada nothing) documentation on any of this... what can I do... I'll see if I can hack around this crap.

(edit) Yep rage . The selectparameters are set initially, which causes the event. Perhaps I've to cache them as well... will try that (as this is all trial/error anyway, what a wonderful framework... asp.net)

(edit) Ok, decompiling ObjectDataSourceView seems to reveal that they're using the selectparameters as a key in the equation if they've to select again. Or better: the code called has to figure that out.

I'll cache the parameter values and based on that check if the values have been changed. See if that works around it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 14:25:50   

Ok, I've now managed to cache the original selectparameter values, and when I change the second drop down (products) or click a button (thus arrange a postback), NO select is performed, as no select parameter has been changed. However, it still reverts to the first item in the list after that!!!

I'll now disable the OnParametersChanged event handler, to see if that makes any difference. (as it now always raises the datasource changed event, like the objectdatasource does)

(edit) when I do that, the second combobox isn't refreshed as the datasource isn't reloading itself. So that's not it.

(edit) OK! EnableViewState==false PRESERVES the viewstate, thus keeps the selected value, setting it to true (default), ALWAYS reverts to the top item.

Amazing, how stupid asp.net sometimes is. All I do is return the SAME data in the same object (entityview).

My change to cache the selectparametervalues to make this happen is available in the next build (due later today or tomorrow) and you then have to set EnableViewState to false on the combobox with the selectparameter.

I of course might have missed some low-level elite property somewhere in this asp.net mess....

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 14:47:44   

Just to signal how #&$^#*@$@ broken asp.net is: - I have in the same project (webproject) also another page, which has 2 comboboxes (one with countries hardcoded, other filled with customers) and a grid. (default.aspx) - When I debug that page (so it's in the same PROJECT!), I suddenly can't step into the ormsupportclasses code anymore, while when I debug the other page with the 2 comboboxes which I used to test this error (default12.aspx) I can. Same debug session, same code, same project, though the default.aspx page apparently uses a completely different code base. It also doesn't work. (runtime).

Then I close everything, stop/start w3svc, load the solution again, rebuild, and voila, default.aspx allows me to debug and it now works.

Magic? frowning

I feel sorry for the people who have to work with asp.net every day. I can't imagine how much time people loose because of these little things which fall apart or aren't documented etc.

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 22-Sep-2006 15:17:10   

Hehe, welcome to my world. I am just glad that the controls that I place on the designer surface are there the next time I open the project and that the event handlers that I code dont get dropped by the CodeDom.

It sounds like you made some good progress though.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 15:58:41   

Devildog74 wrote:

Hehe, welcome to my world. I am just glad that the controls that I place on the designer surface are there the next time I open the project and that the event handlers that I code dont get dropped by the CodeDom.

Yeah I don't envy you simple_smile .

It sounds like you made some good progress though.

It seems to work indeed simple_smile . I'm not sure if it fixes your other problem in this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7650

Frans Bouma | Lead developer LLBLGen Pro