public static void Confirmation(string message)
{
// Cleans the message to allow single quotation marks
string cleanMessage = message.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">var confirmation=this.document.getElementById('hfConfirmation'); if(confirm('" + cleanMessage + "'))confirmation.value='Yes' else return confirmation.value='No';</script>";
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}
}
is my .aspx page has a hiddenfield control with ID hfConfirmation
due to need doing some tricks if the user click yes perform Action 1 else perform Action 2.
But this code is doesn't work.
Any idea or better idea to modify this code without applying the HiddenField also able to retrieve the confirm value.?