Link to home
Start Free TrialLog in
Avatar of jfsedlar3rd
jfsedlar3rdFlag for United States of America

asked on

Change control state from db value.

I am working on an ASP.NET site. My site has a complex model for the state of the controls depending on the status the record is in. I have multiple AD groups linked to the respective status that they can access.  I am adding another layer to the linker table which will store an ID of a linker table that holds the Control and the state. From code how can I enable,disable and readonly the control without building a huge case statement which contains every control name. Is there a class model i can use that will take the name of the control and the state i want the control to be in from the db?
Avatar of TSmooth
TSmooth

Why not just sue the Page.FindControl() and/or Control.FindControl() methods?
http://msdn.microsoft.com/en-us/library/31hxzsdw.aspx

Then for each database record, you call findcontrol using the value from your data row's id column and set the appropriate value on that control.
Avatar of jfsedlar3rd

ASKER

I think I can make this work thank you. But I will still have to have a case statement for control type.

Select Caset db.ControlType

Case TextBox

 CType(Page.FindControl("ControlName"), TextBox).Visible = False
 
Case Button

 CType(Page.FindControl("ControlName"), Button).Visible = False
 
Case DropDownList

 CType(Page.FindControl("ControlName"), DropDownList).Visible = False
 
End Select
Actually that wont work cause the property e.g. visible,readonly etc can change too.
ASKER CERTIFIED SOLUTION
Avatar of TSmooth
TSmooth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial