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
    Hi,
    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;
    else
    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
    https://www.pyarb.com

  • #765932
    Hi,

    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();
    if(role=="Admin")
    $("#btnDelete").attr("disabled", true);
    else
    $("#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;
    else
    btnDel.Disabled = false;

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

  • #765938
    Hi,
    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:
    http://net-informations.com/q/faq/passvalues.html
    2. After this get that passed value on 2nd form and code accordingly [Use code posted above by our DNS members].

  • #766184
    Hi
    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);
    sqlcmd.Fill(Dt);
    Session["AdminRights"] = Dt.DefaultView[0]["AdminRights"].ToString();



    Checking Rights



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


    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

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

  • #766186
    Hi,

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


    if(UserRole=="Admin)
    btnEdit.Enable=true;
    else if(UserRole=="User")
    btnEdit.Enable=false;

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

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments