Well in our project we are having a requirement as to create a global class file, In each of our ASPX.cs page we have to pass the page controls (Page.Controls) to the global class file i mentioned above, and i need to disable or enable the controls in the class. This can be simply done in each of the ASPX.cs page as,
but_edit.enable = false;
but_delete.enable = false;
*Where but_edit and but_delete are two buttons in the ASPX page.*
Instead of defining this in each of the pages, i need to create a global class, so that i can pass the controls (like Textbox,Imagebutton) of each page to that class. In ASPX page,
<asp:ImageButton ID="but_edit" runat="server" ImageUrl="~/Images/Admin/editbtn.png"
OnClick="btnsavelocation_Click" CssClass="btn1" />
<asp:ImageButton ID="but_close" runat="server" ImageUrl="~/Images/Admin/deletebtn.png"
CssClass="btn2" OnClick="btnclose_Click" />
This is what i have done in each of the ASPX.cs page,
Authorization assign_auth = new Authorization();
assign_auth.ChangeControlStatus(Page.Controls);
where Authorization is the class and ChangeControlStatus is the the method. This is my code in the common class page,
public class Authorization
{
public void ChangeControlStatus(ControlCollection PageControls)
{
foreach (Control ctrl in PageControls)
{
string controlType = (ctrl.GetType()).Name;
if (ctrl is Button)
{
Button but = (Button)ctrl;
but.Enabled = false;
}
}
}
}
And now,here its possible to enable or enable a control,like all Imagebuttons in the page. but is it possible to enable or disable a control based on the id (since I have specified the same id in all pages in our project)
The main reason for this is,in our project where there are users with many roles who can access the same pages,based on the role some can have access to EDIT and not to DELETE so need to work on this...
Hope I explained clearly..