I am working on an ASP.Net C # application, I wanted to create a Button control when a user clicks a button, a JavaScript confirmation popup window, then receives a logical value from the user (yes / no) to perform further actions in the onClick event on the button.
In my current approach, the OnClientClick and OnClick events were added in the button where the OnClientClick launch function is launched and the value (Yes / No) is stored in the HiddenField Control for use during the OnClick event.
This is something like the following code snippets:
function CreatePopup(){ var value = confirm("Do you confirm?"); var hdn1 = document.getElementById('hdn1'); hdn1.Value = value; } <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="CreatePopup()"/> <asp:HiddenField ID="hdn1" runat="server" />
Is there a better approach for this? thank you in advanced condition.
source share