Archives / 2009 / January
  • Hiding some page controls from the Unauthenticated users

    If you want to hide controls in the page that is being displayed by the logged in and not logged in users , then you can check the Request.IsAuthenticated property which returns true if the user is logged in ( of course you must be using Windows or Forms authentication). For example, If you want to hide a button from the anonymous users , you can write : Button1.Visible=Request.IsAuthenticated; If you have many controls that you want to hide , you can group them inside a Panel : Panel1.Visible=Request.IsAuthenticated; This will hide the Panel including the controls inside it.

  • The 'SkinId' property can only be set in or before the Page_PreInit event for static controls

    If you get that error , then you would probably is trying to set the SkingId programatically.Note that if you are adding your control dynamically, you should assing that proeprty before adding the control to it's parent.I noticed this issue also when the developers trying to set the skinId for the controls that are inside another controls like GridView,Datalist,Repeater,ListView ....

  • How to select an item in Listview based on the DataKey

    If you want to Select a listView item based on a Key , you can handle it's ItemDatabound event like below:
    private int YourKeyValue = 3;
    protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    if (e.Item.ItemType == ListViewItemType.DataItem)
    ListViewDataItem di =(ListViewDataItem) e.Item;
    int CurrentItemValue = int.Parse(ListView1.DataKeys[di.DataItemIndex].Value.ToString());
    if (CurrentItemValue == YourKeyValue)
    ListView1.SelectedIndex = di.DataItemIndex;