Start New Discussion within our Software Development Community
protected
 


override void OnPreInit(EventArgs e)
 
  {
 
     
 

base.OnPreInit(e);
 
     
 

switch (Session["role"].ToString())
 
      {
 
         
 

case "X":
 
              MasterPageFile =
 

"X.Master";
 
             
 

break;
 
         
 

case "SS":
 
              MasterPageFile =
 

"SS.Master";
 
             
 

break;
 
 
 
default:
 
              MasterPageFile =
 

"XS.Master";
 
             
 

break;
 
      }
 
    
 

if (Session["role"].ToString() == "SS")
 
      
 
         {     btnSearch.Enabled =
 

true;
 
                rbSerial.Checked =
 

false;
 
                rbName.Checked =
 

false;
 
             }
 
        
 

else 

           {
 
               btnSearch.Enabled =
 

false;
 
           
 
             }
 
            
 
      }
 
  protected void rbSerial_CheckedChanged(object sender, EventArgs e) {    
   if (rbSerial.Checked) {
    txtSerial.Enabled = true;

please advice

hi,
into this class (or form) you pass a role value (what ever string or integer type), and based on that you can then use if/else if statements or swith, like you already showed us in your code.
Do it as:

//on form1:
//pass a role variable to form1, from login form!
public Form1()
{
    //main constructor
    InizializeComponent();
}

public Form1(string role)
   : this();
{     
     //additional constructor
     //1st the main constructor`s code will executed, then this one!
     SettingRoles(role)     
}

private void SettingRole(string role)
{
     switch(role)
     {
         case "admin":
         {
              //set it by your self!!
              button1.Visible = true;
              break;
         }
         case "user":
         {
              //set it by your self!!
              button2.Visible = true;
              break;
         }
     }     
}
This article has been dead for over six months. Start a new discussion instead.