Conditional webform controls

Discussion in 'ASP .Net Web Controls' started by Jerod Guida, Feb 9, 2005.

  1. Jerod Guida

    Jerod Guida Guest

    I am fairly new to asp.net and am using webforms in vb.net. I have read a
    lot about authorization to entire pages using role-based security, but I
    haven't seen much in regard to role-based security for controls within a
    page.

    For example, say that I want an aspx page to show a link for "Maintenance"
    when the user "John" is logged in but not for anyone else. All users have
    authorization to see the aspx page (set in web.config), but how does someone
    go about the process of conditionally displaying the link? My question is
    generic in that I don't specifically care about the link, rather, I am
    looking for something that could be applied to any type of control
    (textboxes, buttons, etc) within webforms.

    Thanks in advance,
    Jerod
    Jerod Guida, Feb 9, 2005
    #1
    1. Advertising

  2. Jerod Guida

    Arthur Dent Guest

    You could use either of the following methods, where you have any control
    named c:

    c.Visible = User.Identity.Name = "AllowedUserName"
    - or -
    c.Visible = User.IsInRole("MyAllowRole")

    You could then combine this with a user control, or a panel to make a whole
    block of the page show/hide, instead of just one control.

    HTH.

    "Jerod Guida" <> wrote in message
    news:%...
    >I am fairly new to asp.net and am using webforms in vb.net. I have read a
    > lot about authorization to entire pages using role-based security, but I
    > haven't seen much in regard to role-based security for controls within a
    > page.
    >
    > For example, say that I want an aspx page to show a link for "Maintenance"
    > when the user "John" is logged in but not for anyone else. All users have
    > authorization to see the aspx page (set in web.config), but how does
    > someone
    > go about the process of conditionally displaying the link? My question is
    > generic in that I don't specifically care about the link, rather, I am
    > looking for something that could be applied to any type of control
    > (textboxes, buttons, etc) within webforms.
    >
    > Thanks in advance,
    > Jerod
    >
    >
    Arthur Dent, Feb 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. titof
    Replies:
    0
    Views:
    490
    titof
    Jul 24, 2003
  2. timmso
    Replies:
    1
    Views:
    470
    Alex Papadimoulis
    Dec 12, 2003
  3. Alec S.
    Replies:
    10
    Views:
    10,091
    Alec S.
    Apr 16, 2005
  4. =?Utf-8?B?bXN1aw==?=

    Using one webform to set a value on another webform

    =?Utf-8?B?bXN1aw==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    445
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 12, 2006
  5. =?Utf-8?B?Vk1J?=

    Moving value from popup Webform to main Webform?

    =?Utf-8?B?Vk1J?=, Oct 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    558
    GroupReader
    Oct 9, 2006
Loading...

Share This Page