954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Dynamically get All controls (and it’s IDs) in an aspx Page?

HEllo, I need to dynamically activate fields in a page according to the service that is going to be executed...

Let me explain:

There's a page with all the possible fields and a ListBox with all the selected services to be executed, then when the user selects which service to execute (change a car plate, for example), then I need to activate only the field(s) that the service require... (The realationship between Services and Fields are stored in a database).

public void CheckAll(int pService_Id, Control pPage)
{

    foreach (Control control in pPage.Controls)
    {
        busExecutaServico vExecuta = new busExecutaServico();

        if (vExecuta.EnableField(control.ID.ToString(), Convert.ToInt32(listBoxServices.SelectedValue)))
        {
            switch (control.GetType().ToString())
            {
                case "TextBox":
                    TextBox controleText = (TextBox)Page.FindControl(control.ID.ToString());
                    controleText.Enabled = true;
                    break;


Note that busExecutaServico is the class which contains the method (EnableField) for checking if the selected item matches any field on the database..

I can't seem to get the control.ID.ToString() to work properly (the ID always comes as NULL)

If anyone can help me solve this, or if there's another way (even if it's completely different from what i'm trying), it would be of great help. thanks

ssalsicha
Newbie Poster
1 post since May 2009
Reputation Points: 10
Solved Threads: 0
 

You may need this question in ASP.NET forum http://www.daniweb.com/forums/forum18.html they will help you more I have no more than recommending you to debug and discover why Null comes...

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You