change an attribute of all controls, before the page renders

Discussion in 'ASP .Net' started by neilmcguigan@gmail.com, Mar 23, 2006.

  1. Guest

    i want to enumerate all server controls in a page

    if it has a text property, change it

    right before the page is sent to the browser

    how do i do this?

    i take it i have to override something like page.Render()...

    thanks!

    neil
    , Mar 23, 2006
    #1
    1. Advertising

  2. q Guest

    What attribute? You can very easily iterate in ECMAScript (JavaScript)
    as well...
    q, Mar 24, 2006
    #2
    1. Advertising

  3. Guest

    the Text property

    i want to do this on the server, not client
    , Mar 27, 2006
    #3
  4. Jared Guest

    There may be an easier way, but if you chose a numeric naming
    convention for your fields, than you can loop through them.

    e.g.
    str1, str2 //for text box
    ddl1, ddl2 //for drop down list

    CODE...

    Page pgPage = this.Page; //or pass the page into the procedure if you
    are using a class.

    int intControl = 1;
    int intControls = 55 //If you have 55 controls on your page

    while(intControl <= 55)
    {
    TextBox strTextBox = pgPage.FindControl("str" + intControl) as TextBox;
    strTextBox.Text = "Test"; //Set the value to whatever you want it to be
    intControl += 1; //Move to the next control
    }

    //Repeat for DropDownLists and other control types, e.g.

    while(intControl < 55)
    {
    DropDownList strDropDownList = pgPage.FindControl("ddl" + intControl)
    as DropDownList;
    strDropDownList.SelectedValue = "Test"; //Set the value to whatever you
    want it to be
    intControl += 1; //Move to the next control
    }

    In my application I have a whole load a variables for controls, so I
    store them in a database table along with the control ID and perform
    the same loop, but through a recordset.

    Hope this is useful.

    Jared
    Jared, Mar 27, 2006
    #4
    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. Guest
    Replies:
    4
    Views:
    7,126
    Steven Cheng[MSFT]
    Nov 9, 2005
  2. PJ
    Replies:
    0
    Views:
    538
  3. TS
    Replies:
    2
    Views:
    999
  4. Nigil LaVey
    Replies:
    0
    Views:
    95
    Nigil LaVey
    Nov 5, 2003
  5. Craig
    Replies:
    1
    Views:
    114
    Craig
    Sep 15, 2005
Loading...

Share This Page