views:

349

answers:

1

I have a dropdownlist on an ASP.NET web form. It is set to autopostback and viewstate is enabled. When I run my project from Visual Studio I can change the value, pick up the new value in the postback and display some related results in a grid (Infragistics). I can keep changing the value and the grid updates correctly.

When I copy this from my test/dev box to the live Windows 2008 server, all changes. The first change to the dropdown causes a postback but the grid doesn't get updated because the dropdownlist's SelectedIndexChanged event does not fire. The second change clears the dropdown altogether.

The items in the dropdown are created when the page first loads as simple ListItems that are added to the control's Items collection. The values are retrieved from a Microsoft CRM system but not data-bound.

Can anybody explain what is going wrong and why the behaviour in Visual Studio would be different to that when live?

    protected void Page_Load(object sender, EventArgs e)
    {
        _crm = GetCrmConnection();

        if (!IsPostBack)
        {
            ShowDepotList();
            ShowJobsForCurrentDepot(); // Updates the grid - not shown in SO
        }
    }


    private void ShowDepotList()
    {
        List<BusinessEntity> depots = _crm.GetDepots();
        foreach (DynamicEntity depot in depots)
        {
            string depotName = depot.Properties["dpt_name"].ToString();
            string locationName = depot.Properties["dpt_locationname"].ToString();

            ListItem depotListItem = new ListItem
            {
                Text = string.Format("{0} - {1}", depotName, locationName),
                Value = ((Key)depot.Properties["dpt_sitedetailid"]).Value.ToString()
            };

            DepotInput.Items.Add(depotListItem);
        }
   }


   protected void DepotInput_SelectedIndexChanged(object sender, EventArgs e)
   {
        ShowJobsForCurrentDepot();
   }
+2  A: 

If you're sure that the code on the test machine and the live machine is the same - are you sure that the web.config is the same too?

You can switch ViewState on and off in the web.config:

<pages enableViewState="false" />

You might possibly have it switched on when developing, but switched off on the live web.config.

Alex York
It was CRM's web.config disabling viewstate, thanks :)