Hi
I have below code and i want to pass multiple parameters to User Control . In User Control i have modal defined
C#
string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' ";
htmlTable.Append($"");Code
×
Cancel
Delete--%>Thanks

Naimish MakwanaRank #324 · 7.7K reputationPosted Aug 28, 2024, 7:57 AM EDT
To pass multiple parameters to the User Control dynamically, you can use HTML data attributes in combination with JavaScript to transfer the data to the modal. Here's how you can modify your code:
1. Modify the Link Button with Additional Data Attributes:
Update your link button to include additional data attributes that will hold the
IdandTableNameor any other parameters you need to pass.string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' "; htmlTable.Append($"");2. Capture the Data in JavaScript:
You can use JavaScript to capture these data attributes when the modal is triggered and set them in the modal's controls.
$(document).ready(function () { $('#modal_Delete').on('show.bs.modal', function (event) { var button = $(event.relatedTarget); // Button that triggered the modal var recno = button.data('recno'); var sp = button.data('sp'); var id = button.data('id'); var table = button.data('table'); // Now set these values in the modal var modal = $(this); modal.find('.modal-title').text('Delete record ' + id); // If you want to pass these to hidden fields or labels inside the modal modal.find('#hiddenFieldRecno').val(recno); modal.find('#hiddenFieldSp').val(sp); modal.find('#hiddenFieldId').val(id); modal.find('#hiddenFieldTable').val(table); }); });3. Modify the Modal Markup:
Make sure your modal has controls (e.g., hidden fields or labels) where these values will be assigned.
× Cancel Delete4. Accessing Parameters in the Code-Behind:
You can access these parameters in the code-behind when the delete button is clicked.
protected void lnkRecordDelete_Click(object sender, EventArgs e) { string recno = hiddenFieldRecno.Value; string sp = hiddenFieldSp.Value; string id = hiddenFieldId.Value; string table = hiddenFieldTable.Value; // Perform delete operation using these values }This approach allows you to dynamically pass multiple parameters to your User Control modal and handle them as needed in your ASP.NET application.