Disable all controls in...

Discussion in 'ASP .Net' started by Edwin Knoppert, Jan 22, 2006.

  1. I have a div which holds controls.
    I'm looking for a way to disable all controls but *without* setting each
    control enable state.
    Same to style>display i'm looking for a disable method.

    Do i need a container control for this?
     
    Edwin Knoppert, Jan 22, 2006
    #1
    1. Advertising

  2. Hi Edwin,

    Yes, using a Panel WebControl would probably be a good way to solve your
    problem.

    Groete,
    Peter

    Peter McMahon
    http://www.dotnet.za.net

    "Edwin Knoppert" <> wrote in message
    news:dr0tpb$99r$...
    >I have a div which holds controls.
    > I'm looking for a way to disable all controls but *without* setting each
    > control enable state.
    > Same to style>display i'm looking for a disable method.
    >
    > Do i need a container control for this?
    >
    >
     
    Peter McMahon, Jan 22, 2006
    #2
    1. Advertising

  3. You can use a container control or make the div a server side control:

    <body>
    <form id="form1" runat="server">

    <div id="div1" runat="server">

    <asp:TextBox ID="TextBox1" runat="server" />

    <asp:Button ID="Button1" runat="server" />

    </div>

    </form>

    </body>

    div1.Visible = false;


    --
    Andrew Robinson
    http://blog.binaryocean.com


    "Edwin Knoppert" <> wrote in message
    news:dr0tpb$99r$...
    >I have a div which holds controls.
    > I'm looking for a way to disable all controls but *without* setting each
    > control enable state.
    > Same to style>display i'm looking for a disable method.
    >
    > Do i need a container control for this?
    >
    >
     
    Andrew Robinson, Jan 23, 2006
    #3
  4. Thanks, will check!

    :)


    "Peter McMahon" <> schreef in bericht
    news:...
    > Hi Edwin,
    >
    > Yes, using a Panel WebControl would probably be a good way to solve your
    > problem.
    >
    > Groete,
    > Peter
    >
    > Peter McMahon
    > http://www.dotnet.za.net
    >
    > "Edwin Knoppert" <> wrote in message
    > news:dr0tpb$99r$...
    >>I have a div which holds controls.
    >> I'm looking for a way to disable all controls but *without* setting each
    >> control enable state.
    >> Same to style>display i'm looking for a disable method.
    >>
    >> Do i need a container control for this?
    >>
    >>

    >
    >
     
    Edwin Knoppert, Jan 23, 2006
    #4
  5. I did the same, like i said, visible does work, disabling instead.. how?



    "Andrew Robinson" <> schreef in bericht
    news:%...
    > You can use a container control or make the div a server side control:
    >
    > <body>
    > <form id="form1" runat="server">
    >
    > <div id="div1" runat="server">
    >
    > <asp:TextBox ID="TextBox1" runat="server" />
    >
    > <asp:Button ID="Button1" runat="server" />
    >
    > </div>
    >
    > </form>
    >
    > </body>
    >
    > div1.Visible = false;
    >
    >
    > --
    > Andrew Robinson
    > http://blog.binaryocean.com
    >
    >
    > "Edwin Knoppert" <> wrote in message
    > news:dr0tpb$99r$...
    >>I have a div which holds controls.
    >> I'm looking for a way to disable all controls but *without* setting each
    >> control enable state.
    >> Same to style>display i'm looking for a disable method.
    >>
    >> Do i need a container control for this?
    >>
    >>

    >
    >
     
    Edwin Knoppert, Jan 23, 2006
    #5
  6. Edwin,

    Only ASP.NET server controls contain the Enabled property. If you are using
    all server side controls, you can do the following:

    <body>
    <form id="form1" runat="server">
    <div>
    <asp:placeHolder ID="PlaceHolder1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </asp:placeHolder>
    </div>
    </form>
    </body>

    in code:

    foreach (WebControl control in PlaceHolder1.Controls)
    {
    control.Enabled = false;
    }

    If you attempt to use this with an HTML control such as an <IMG> or <INPUT>
    tag, you will throw an InvalidCastException.

    Hope this helps.

    --

    Andrew Robinson
    http://blog.binaryocean.com

    "Edwin Knoppert" <> wrote in message
    news:43d497ec$0$12844$...
    >I did the same, like i said, visible does work, disabling instead.. how?
    >
    >
    >
    > "Andrew Robinson" <> schreef in bericht
    > news:%...
    >> You can use a container control or make the div a server side control:
    >>
    >> <body>
    >> <form id="form1" runat="server">
    >>
    >> <div id="div1" runat="server">
    >>
    >> <asp:TextBox ID="TextBox1" runat="server" />
    >>
    >> <asp:Button ID="Button1" runat="server" />
    >>
    >> </div>
    >>
    >> </form>
    >>
    >> </body>
    >>
    >> div1.Visible = false;
    >>
    >>
    >> --
    >> Andrew Robinson
    >> http://blog.binaryocean.com
    >>
    >>
    >> "Edwin Knoppert" <> wrote in message
    >> news:dr0tpb$99r$...
    >>>I have a div which holds controls.
    >>> I'm looking for a way to disable all controls but *without* setting each
    >>> control enable state.
    >>> Same to style>display i'm looking for a disable method.
    >>>
    >>> Do i need a container control for this?
    >>>
    >>>

    >>
    >>

    >
    >
     
    Andrew Robinson, Jan 23, 2006
    #6
  7. Edwin Knoppert

    dayalaman

    Joined:
    Dec 4, 2007
    Messages:
    1
    Enable Disable, all controls inside a div / placeholder

    ASPX Page:

    Code:
     <asp:PlaceHolder ID="placeHolderMyServerControl" runat="server"></asp:PlaceHolder>
    Code Behind:

    Call Function:
    Code:
    
    private bool condition;
    
    protected override void CreateChildControls()
    {
       base.CreateChildControls();
       MyServerControl serverControl = new MyServerControl();
       placeHolderMyServerControl.Controls.Add(serverControl);
    }
    
    protected override void OnPreRender(EventArgs e)
    {
      base.OnPreRender(e);
      MyCondition();
      if(condition == true)
      {
         EnableControl(true, placeHolderMyServerControl.Controls);
      }
      else
      {
         EnableControl(false, placeHolderMyServerControl.Controls);
      }
    }
    
    
    
    Create Function:
    Code:
    /// <summary>
    /// Enable Disable Control
    /// </summary>
    /// <param name="enabled">true or false</param>
    /// <param name="controls">Controls Collection</param>
     private void EnableControl(bool enabled, ControlCollection controls)
            {
               foreach (Control childControl in control)
               {
                   try
                   {
                       WebControl webChildControl = (WebControl) childControl;
                       webChildControl.Enabled = enabled;
                   }
                   catch
                   {
                       
                   }
                   finally
                   {
                       EnableControl(enabled, childControl.Controls);
                   }
               }
            }
    
    
    //Your Condition
    private void MyCondition()
    {
    //Put your own if condition
      if()
      {
       condition = true;
      }
      else
      {
       condition = false;
       }
    }
    
    
    
    =============

    :driver:
    I have more posts like these on rudebox.editboard.com <- My forum ;)
     
    Last edited: Dec 4, 2007
    dayalaman, Dec 4, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    472
  2. Guest
    Replies:
    4
    Views:
    7,229
    Steven Cheng[MSFT]
    Nov 9, 2005
  3. Replies:
    4
    Views:
    11,672
  4. Evan M.

    Disable all form controls

    Evan M., Aug 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    207
    Evan M.
    Aug 18, 2005
  5. Bart Van der Donck

    disable all elements from all forms except <textarea>'s

    Bart Van der Donck, Feb 1, 2005, in forum: Javascript
    Replies:
    3
    Views:
    125
    Stephen Chalmers
    Feb 1, 2005
Loading...

Share This Page