TheEdge TheEdge - 2 months ago 8
ASP.NET (C#) Question

Getting UniqueID inside OnClientClick() to pass as a parameter to a JS function

I am using a DevExpress grid and the DataItemTemplate for a column as follows:

<DataItemTemplate>
<asp:Button Visible="True" EnableViewState="False" CssClass="btn btn-sm btn-danger" data-confirm="Are you sure you want to delete this Organisation Member?" ID="DeleteButton" data-id="<%#: Container.KeyValue %>" runat="server" Text="Delete" OnClientClick=' return DeleteConfirm("<%= UniqueID %>"); ' OnClick="DeleteButton_OnClick" />
</DataItemTemplate>


I want to pass the unique identifier for the button to my JS function DeleteConfirm() as a parameter.

However instead of the unique identifier I am getting the string <%= UniqueID %>

How get the unique identifier for each button passed a parameter?

Answer

Item within the <%= %> or <%# %> notation cannot be references to properties on that object itself. You should be able to pass this and then use the button directly though:

return DeleteConfirm(this);

The this reference would be the reference to the button.

Comments