You must Sign In to post a response.
  • Category: .NET

    How to disable button

    Now i am create windows based application using c#2010, sql server 2005, Form1 - it's user creation form (name, username, password, rights) here i am using rights combobox control only two list 1.user 2.admin.

    once create a user after that go to login page, enter user name & password & rights(user/admin) i am select user after goes to forms i am enter product stock form using user rights that time "Edit button" disable than again logout and goes to admin rights click same form i want edit button enable how to create. give me any one ideas.
  • #765921
    Thanks for posting here. I am not sure how you are storing Roles in your Windows Application. But you can apply a conditional logic to display or change the functionality of Button.

    if(userRole == "Admin")
    btnDelete.Visible = true;
    btnDelete.Visible = false;

    If you are still unable to apply your logic, please share your code, we will help you getting your desired result.

    Glad to be,
    John Bhatt
    Editor - DNS Forums

  • #765932

    You can do this by client side script using jquery as well.
    Please find below code snippet for the same.

    var role=$( "#ddlRole option:selected" ).text().trim();
    $("#btnDelete").attr("disabled", true);
    $("#btnDelete") .removeAttr("disabled");

  • #765933
    so basically depend upon the rights you need to disable or enable Button. it is simple and basic

    if(UserRight != "Admin")
    btnDel.Disabled = true;
    btnDel.Disabled = false;

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765938
    1. When u r on login form, pass selected rights i.e. (user/admin) to 2nd form where you enter product stock.
    Refer this link for techniques to pass data within windows forms:
    2. After this get that passed value on 2nd form and code accordingly [Use code posted above by our DNS members].

  • #766184
    Get the value use the code

    DataTable Dt = new DataTable();
    SqlDataAdapter sqlcmd = new SqlDataAdapter("select username,password,AdminRights where users='" & TxtUSerName.Text & "' and Password='" & TxtUSerName.Text & "'", con);
    Session["AdminRights"] = Dt.DefaultView[0]["AdminRights"].ToString();

    Checking Rights

    //checking Rights
    if (Session["AdminRights"] == "Yes")
    //Allow Enable
    //Disable use

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766186

    If you want to enable disable button based on user permission level then refer below sample code.

    else if(UserRole=="User")

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments