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

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 1
Reputation: ssalsicha is an unknown quantity at this point 
Solved Threads: 0
ssalsicha ssalsicha is offline Offline
Newbie Poster

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

 
0
  #1
May 17th, 2009
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).

  1. public void CheckAll(int pService_Id, Control pPage)
  2. {
  3.  
  4. foreach (Control control in pPage.Controls)
  5. {
  6. busExecutaServico vExecuta = new busExecutaServico();
  7.  
  8. if (vExecuta.EnableField(control.ID.ToString(), Convert.ToInt32(listBoxServices.SelectedValue)))
  9. {
  10. switch (control.GetType().ToString())
  11. {
  12. case "TextBox":
  13. TextBox controleText = (TextBox)Page.FindControl(control.ID.ToString());
  14. controleText.Enabled = true;
  15. 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

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

 
0
  #2
May 18th, 2009
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...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC