Hi
I have below code in Department.aspx. How i will pass Id & Table Name to Delete Modal which is User Control
string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'";
htmlTable.Append($"");
Thanks
Ramco RamcoPosted Aug 28, 2024, 7:39 AM
Hi Naimish
I want to pass these 2 fields. How i should pass in below code to User Control. Please help me
Int32 recno = Convert.ToInt32(Common.CommonFunction.EncodePasswordToBase64(row["docno"].ToString()));
string sp = Common.CommonFunction.EncodePasswordToBase64("sp_Inv");
Thanks
Naimish MakwanaPosted Aug 28, 2024, 5:07 AM
Yes, you can encrypt the values like
UserIdandTableNamebefore passing them to the user control or through HTML attributes. To achieve this, you would use AES encryption in your code. Here's how you can implement it:Step 1: Implement AES Encryption
First, implement an AES encryption method. Below is an example of how you can do this:
AES Encryption Helper Class:
Step 2: Encrypt Values in Your Code
Now, use this encryption method to encrypt the
UserIdandTableNamebefore passing them:Step 3: Update BindData Function to Decrypt (if necessary)
If you need to decrypt these values on the client side, you would typically pass them back to the server where they would be decrypted. For example, if you want to bind data in your server-side method, you can decrypt the values as follows:
BindData Method:
Step 4: Ensure the Decrypt Method Exists
Just as you encrypt the values, ensure you have a corresponding
Decryptmethod in theAESclass:With this setup, your
UserIdandTableNamewill be encrypted before being passed to the modal, and you can decrypt them on the server side if necessary. This adds a layer of security to the data being passed in the HTML.Thanks
Ramco RamcoPosted Aug 28, 2024, 4:59 AM
Hi Naimish
Can the values be encrypted like below
AES.Encrypt(colum.UserID.ToString())
Thanks
Naimish MakwanaPosted Aug 28, 2024, 4:54 AM
To pass the
IdandTable Namedirectly to a user control (e.g., the delete modal), you can modify the user control to accept these values via properties or methods. Here's how you can achieve that:Step 1: Modify the User Control
Assuming the modal is encapsulated in a user control (
DeleteModal.ascx), you can create public properties to accept theIdandTable Name:DeleteModal.ascx.cs (Code-Behind):
Step 2: Modify the Delete Button
Instead of using JavaScript, you can directly set the properties of the user control when generating the HTML:
Department.aspx.cs:
Step 3: Update the BindData Method
Ensure that the
BindDatamethod in the user control is called to pass the values:Department.aspx.cs (Inside the Page_Load or any other event handler)
Step 4: Modify the User Control's Frontend
Ensure your user control is integrated with your modal setup:
DeleteModal.ascx:
Step 5: Trigger the Modal with Parameters
Make sure the modal is correctly linked to the properties you've set:
By using this approach, the
IdandTable Namewill be passed directly to your user control, and the modal will be prepared with the correct information without needing client-side scripts to pass the data.Thanks
Ramco RamcoPosted Aug 28, 2024, 4:24 AM
Hi Naimish
How i cna directly pass Id & Table name to user control in below code
Thanks
Naimish MakwanaPosted Aug 28, 2024, 4:18 AM
To pass the
IdandTable Nameto the delete modal, you can use data attributes to store these values and then retrieve them in the JavaScript functionBindData. Here’s how you can modify your code:1. Modify the
deleteAttributesstring to include data attributes forIdandTable Name:2. Update the
BindDataJavaScript function to retrieve these data attributes and set them in the modal:3. Add hidden fields in the modal to store these values if needed:
4. Update the
lnkRecordDelete_Clickevent handler in your code-behind to use these hidden fields:This approach ensures that the
IdandTable Nameare passed to the modal and can be used in your delete logic.Thanks