1

I am working in an ASP.NET WebForms application built in VB.NET.

Depending on the role of the current logged in user I want to disable the TextBox. So If he/she is part of Role A, then he / she will be able to edit the content of the TextBox, otherwise the TextBox is disabled.

<asp:TextBox runat="server" 
             ID="txtResolution" 
             CssClass="newTextObject" 
             TextMode="MultiLine">
</asp:TextBox>

How can I achieve this?

1
  • 2
    Make sure you do additional server-side checks. A disabled field can be circumvented to allow data entry. Commented Oct 8, 2013 at 15:20

3 Answers 3

5

You can use the User.Identity.IsInRole() method to check if the current logged in user is a member of the role you require.

The following code should work in the PageLoad method of the page.

If User.Identity.IsInRole("Role A") Then
    txtResolution.Enabled = False
End If

See MSDN documentation of HttpContext.User Property for some more detail on the HttpContext.User property of web applications.

Sign up to request clarification or add additional context in comments.

Comments

2

Assuming you are using Role Management, you just enable the text box if the user is in Role A.

txtResolution.Enabled = User.IsInRole("A")

MSDN IsInRole method

Comments

2

You can set the property

To disable:

txtResolution.Enabled = "false"

To enable:

txtResolution.Enabled = "true"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.