Hi
How we can make delete modal dynamic in asp.net c#
Thanks
Hi
How we can make delete modal dynamic in asp.net c#
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Aman GuptaPosted Aug 27, 2024, 7:06 AM
Hi Ramco,
To create a reusable delete modal that can handle different tables (like Department and Banks) while being defined only once, you need a way to dynamically determine which table's record is being deleted. Here's how you can achieve that:
1. Create a Reusable User Control for the Modal
2. User Control Code-Behind:
DeleteModal.ascx.csInclude the User Control in Your Web Forms
Include the
DeleteModalUser Control in your Web Forms (e.g., Department and Banks) and configure it dynamically based on the context.Web Form:
Department.aspxWeb Form Code-Behind:
Department.aspx.csWeb Form:
Banks.aspxWeb Form Code-Behind:
Banks.aspx.csThis approach allows you to maintain a single instance of the modal code and dynamically handle deletions based on different contexts.
Ramco RamcoPosted Aug 27, 2024, 7:40 AM
Hi All
If Modal is in User Control , Then Delete functionality will also be in Code behind o User Control. If there are 10 or more forms then i need to pass Table Name also. How it will be known from which table record to be deleted
Thanks
Naimish MakwanaPosted Aug 27, 2024, 7:09 AM
You can write the
lnkRecordDelete_Clickevent handler in either a User Control or a WebForm, depending on your application’s structure and where the delete functionality is needed. Here’s a brief overview of both approaches:1. In a WebForm (ASPX Page)
If the delete functionality is specific to a single page, you can place the code directly in the WebForm’s code-behind file (e.g.,
Default.aspx.cs).Example:
ASPX Page:
Code-Behind (Default.aspx.cs):
2. In a User Control (ASCX)
If the delete functionality is reusable across multiple pages, it’s better to place the code in a User Control.
Example:
User Control (MyUserControl.ascx):
Code-Behind (MyUserControl.ascx.cs):
Including User Control in a WebForm:
Thanks
Ramco RamcoPosted Aug 27, 2024, 6:45 AM
Hi Aman/Naimish
I want below code to be written only once not in every form.
Now I have 2 different Web Forms Department & Banks. How it will known from which table record to be deleted
Thanks
Thanks
Aman GuptaPosted Aug 27, 2024, 6:11 AM
Hi Ramco,
The lnkRecordDelete_Click event handler code should be written in the code-behind file of the Web Form or User Control where the delete modal is used. Here's a breakdown to help determine where this code should be placed:
1. If the Modal is Defined in a User Control
User Control Code-Behind: If the modal is part of a User Control (.ascx), and the LinkButton is inside that User Control, then lnkRecordDelete_Click should be defined in the User Control’s code-behind file.
User Control File: YourUserControl.ascx
User Control Code-Behind File: YourUserControl.ascx.cs
2. If the Modal is Defined in a Web Form
Web Form Code-Behind: If the modal is directly included in the Web Form (.aspx), then lnkRecordDelete_Click should be defined in the Web Form’s code-behind file.
Web Form File: YourWebForm.aspx
Web Form Code-Behind File: YourWebForm.aspx.cs
Where to Place the JavaScript Function
The JavaScript function to set the dynamic data for the modal should be placed in the