+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 16 of 16

Thread: Collection of Form Controls

  1. #11
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    I'm not sure what the problem is, R. The method I provided works fine for me from a Web Form when in a Master Page. It also works for me when being called from a UserControl inside a Web Form inside a Master Page.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  2. #12
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Referencing back to your foreach loop example, an easier way to ensure the control is a TextBox (for example):
    Code:
    TextBox tb = ctl as TextBox;
    if (tb != null) {
       // It's a text box, so do textboxy things to it.
    }
    
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #13
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Wolffy View Post
    I may be wrong here (it's before coffee for me), but if you place all the controls you need to Enable/Disable inside an asp:Panel control -- you should be able to just disable the Panel and all its child controls will go with it.

    Otherwise, if you want to disable all the disable-able controls then the following loop takes advantage of these Controls inheriting from WebControl. (tho this is untested):
    Code:
    foreach (Control ctl in Form.Controls) 
    {
       WebControl webctl = ctl as WebControl;
       if (webctl == null) continue;
       webctl.Enabled = false;
    }
    
    I was just on that idea Wolffy!

    I just changed a <div> to a, <aspanel> and have looped through the controls inside that and it worked.

    Will have a look at the code you posted and try that out as well. Not sure if a blanket .Enabled=false will work, but I'll see what happens..

  4. #14
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    I'm not sure what the problem is, R. The method I provided works fine for me from a Web Form when in a Master Page. It also works for me when being called from a UserControl inside a Web Form inside a Master Page.
    Strange. I just did a test writing out each control type it found when called from my web form and it just wrote out the controls from the master page, including the ContentPlaceHolder.

  5. #15
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Wolffy View Post
    Referencing back to your foreach loop example, an easier way to ensure the control is a TextBox (for example):
    Code:
    TextBox tb = ctl as TextBox;
    if (tb != null) {
       // It's a text box, so do textboxy things to it.
    }
    
    It's not just textboxes, it's all form web controls, textbox, dropdown etc.

    Got something working but will play around some more and see what I come up with.

  6. #16
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Wolffy View Post
    I may be wrong here (it's before coffee for me), but if you place all the controls you need to Enable/Disable inside an asp:Panel control -- you should be able to just disable the Panel and all its child controls will go with it.
    I tried this and it almost worked, but just messed up the text on a checkboxlist that is inside a repeater.

    Quote Originally Posted by Wolffy View Post
    Code:
    foreach (Control ctl in Form.Controls) 
    {
       WebControl webctl = ctl as WebControl;
       if (webctl == null) continue;
       webctl.Enabled = false;
    }
    
    I also tried this and it worked apart from not disabling the checkboxlist boxes inside the repeater...

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. User Controls
    By todd2006 in forum .NET Development
    Replies: 51
    Last Post: August 14th, 2009, 10:54 AM
  2. '?companyname' not found in the collection.
    By richyrich in forum MySQL
    Replies: 3
    Last Post: June 19th, 2009, 07:07 AM
  3. loop through a collection
    By Shem in forum .NET Development
    Replies: 15
    Last Post: October 17th, 2008, 11:54 AM
  4. trying to reference my user controls properties?
    By Shem in forum .NET Development
    Replies: 3
    Last Post: October 3rd, 2008, 05:06 AM
  5. Accessing controls in the Footer of a datalist
    By richyrich in forum .NET Development
    Replies: 6
    Last Post: May 12th, 2008, 01:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO