Enable and Disable delete button in LightSwitch Application


Introduction

Normally a Delete button is used to remove unwanted information. Whenever we have unwanted data then we use a delete button. In this article you learn how to disable and enable a delete button in LightSwitch.

Step 1: Open Visual Studio LightSwitch->File->New->Project->Create new table.

image1.gif

Step 2: Now we will make a table like student.

image2.gif

Step 3: Go to Properties in solution explorer.

image3.gif

Step 4: Select Use form authentication->Mark Granted for debug.

image4.gif

Step 5: Right click on screen->Add screen.

image5.gif

Step 6: Select Editable grid screen->Select screen data (student)->Ok.

image6.gif

Step 7: Run Application (Press F5)->Click + sign->Fill data->Ok->Save.

image11.gif

Step 8: Now you can delete any student data using the delete button.

image7.gif

Step 9: If you want to disable the delete button then click write code->Student_CanDelete->Now write the below code.

image8.gif

using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Security.Server;
namespace LightSwitchApplication
{
    public partial class ApplicationDataService
    {
        partial void Students_CanDelete(ref bool result)
        {
            result = this.Application.User.HasPermission(
            Permissions.SecurityAdministration);
        }
    }
}

Step 10: Go to properties in Solution explorer->Use form authentication->Unmark Granted for debug.

image9.gif

Step 11: Run application (Press F5)->Now you can't delete student data because delete button is disabled.

image10.gif

Summary

A Delete button is very useful for remove unwanted data. Whenever we have we have wrong data the we use a delete button. This article is very useful for enable and disable a delete button in LightSwitch Application.


Similar Articles