Knowledgebase
How to hide a control in a webform class?
Posted by z Jean-jacques Jouanneaux on 26 August 2010 04:17 PM

How to hide a control in a webform class (like a column of a datagrid)?

There are 4 options:

1rst. If the object is created statically:

You can change to "false" the property "visible" of the appropriate control, with a Visual Guard "Property Action", created with Visual Guard Console (no coding necessary). (dynamic permission)

2nd. This option consists in coding in a Visual Guard "Script action" (dynamic permission)
This action will execute this script on the appropriate event (for instance "RowCreated") and will change the property "visible" of the column.

Below is an example of script action executed on the event "RowCreated".
It will hide the buttons "Delete" for each rows of a GridView displayed in a webform.

GridViewRowEventArgs e = (GridViewRowEventArgs)eventArgs[1];
if (e.Row.FindControl("DeleteButton") != null)
{
((ImageButton)e.Row.FindControl("DeleteButton")).Visible =false;
}

This is another example of script action executed on the event "ItemCreated".
It will hide the first column of a DataGrid displayed in a webform.
DataGridItemEventArgs e = (DataGridItemEventArgs)eventArgs[1];
e.Item.Cells[0].Visible = false;

Where eventArgs[] is an array generated by Visual Guard when a script action is created.
This array contains the argument list of the event associated to the script action
In the example above, this array contains the arguments of the event "ItemCreated".

3rd option. If the object is created dynamically: (static permission)

You can create a property "col_x_visible" in your object, and you will test this property in your code to display or not this column. (static permission)


4th option: (static permission)
you can check in your program when the user have the permission to see this column.
For example, you can create a permission HidePersonalInformation for your application and you can test if the permission is granted to the current user in your application.

In the ItemCreated event of your datagrid, you can insert the following code:
if (VGSecurityManager.Principal.HasPermission("HidePersonalInformation"))
{
e.Item.Cells[0].Visible = false;
}




Visual Guard .NET

(0 vote(s))
Helpful
Not helpful

Comments (0)
Help Desk by Novalys