ComboBox remains disabled when re-enabled

Last post 08-03-2009 9:16 AM by Greg.Kendall. 3 replies.

Sort Posts:

  • ComboBox remains disabled when re-enabled

    07-31-2009, 10:53 AM
    • Member
      4 point Member
    • Greg.Kendall
    • Member since 07-30-2009, 4:32 PM
    • Posts 6

    We create a ComboBox on a page during Page_Init along with other controls.  When the grid on the page enters edit mode we disable the other controls on the page.  The ComboBox responds just fine to being disabled.  When editing is done on the grid we re-enable the other controls on the page.  All the other controls re-enable but the ComboBox does not.  It remains disabled.

    Debugging seems to show us that the control is accepting the Enabled=true setting and should, to our eyes, be enabled when the page finishes rendering; however, it is still disabled when the page renders.

    Any thoughts?

  • Re: ComboBox remains disabled when re-enabled

    08-01-2009, 11:54 AM
    • Contributor
      3,262 point Contributor
    • basheerkal
    • Member since 06-28-2009, 3:33 AM
    • Kerala, India
    • Posts 772

     Please Check the ComboBox actually remain disabled or  only All its items are cleared. (I mean It is empty)

    Kindly mark this post as "Answer", if it helped you.
  • Re: ComboBox remains disabled when re-enabled

    08-03-2009, 8:26 AM
    • Member
      4 point Member
    • Greg.Kendall
    • Member since 07-30-2009, 4:32 PM
    • Posts 6

    Thanks for the reply.  The items remain (as far as I can see) in the ComboBox. 

    I have recreated the problem with the following app.  Pressing the Toggle button on the app disables both the TextBox and the ComboBox.  Pressing it again  enables them both, but only the TextBox is actually rendered as enabled.  Debugger shows that the code successfully finds and tries to set the Enabled property of both controls.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <asp:Button ID="ToggleButton" runat="server" Text="Toggle" OnClick="ToggleButton_Click" />
        </div>
        </form>
    </body>
    </html>
    

    using AjaxControlToolkit;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebApplication4
    {
       public partial class _Default : System.Web.UI.Page
       {
          protected void Page_Init ( object sender, EventArgs e )
          {
             if (IsPostBack == false)
             {
                Session.Add( "Toggle", false );
             }
            
             TextBox newTextBox = new TextBox();
             newTextBox.ID = "NewTextBox";
             newTextBox.Text = "This is the text";
             form1.Controls.Add( newTextBox );

             ComboBox newComboBox = new ComboBox();
             newComboBox.ID = "NewComboBox";
             form1.Controls.Add( newComboBox );
             newComboBox.Items.Add( new ListItem( "Item 1", "Item 1" ) );
             newComboBox.Items.Add( new ListItem( "Item 2", "Item 2" ) );
             newComboBox.Items.Add( new ListItem( "Item 3", "Item 3" ) );
             newComboBox.Items.Add( new ListItem( "Item 4", "Item 4" ) );

          }

          protected void ToggleButton_Click ( object sender, EventArgs e )
          {
             bool bEnabled = (bool)Session["Toggle"];

             TextBox textBox = (TextBox)form1.FindControl( "NewTextBox" );
             if (textBox != null)
             {
                textBox.Enabled = bEnabled;
             }

             ComboBox comboBox = (ComboBox)form1.FindControl( "NewComboBox" );
             if (comboBox != null)
             {
                comboBox.Enabled = bEnabled;
             }

             Session["Toggle"] = !bEnabled;

          }

       }

    }


     

  • Re: ComboBox remains disabled when re-enabled

    08-03-2009, 9:16 AM
    • Member
      4 point Member
    • Greg.Kendall
    • Member since 07-30-2009, 4:32 PM
    • Posts 6

    Update: I updated the sample app to include an UpdatePanel and add the controls to the UpdatePanel's ContentTemplateContainer.  When I do this the enable/disable works.

    Shouldn't it be reasonable, though, to use ComboBox outside an UpdatePanel on a page?

Page 1 of 1 (4 items)