I need to implement a confirm button in c#.net that I can dynamically set the text as well as the application can understand when the user clicks "Cancel".
I don't want to use a hidden field, if possible.
Currently the only 2 ways I know to use a confirm button in .NET is to either put the button in the "OnClientClick" area of the asp:button, like this.
OnClientClick="return Confirm("The text");
Or to register it using the scriptmanager, like so.
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "return confirm('Add Tax');", true);
I could pass a variable to a hidden field in .NET and then have Javascript pull that field value like this....
function confirmbutton()
{
value = document.getElementByID("HDNField");
if (value ==1)
{
confirm("do you want to eat");
}
if (value ==2)
{
confirm("do you want to sleep");
}
}
This will work, but I prefer a more elegant solution.
CodePudding user response:
