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.?

Can you elaborate some more regarding the process? Im not following exactly..

i want do the javascript confirm function in code behind (Server-side)
and i want retrieve a value which return whether the end-users is click yes or no.

Member Avatar for LastMitch

i want do the javascript confirm function in code behind (Server-side)and i want retrieve a value which return whether the end-users is click yes or no.

@gahhon

I don't follow what you are trying to do either?

You need AJAX do this if you want this to be on the Server-side.

But my question like what JorgeM mention what are you trying to do?

does AJAX can detect whether user is clicked the Yes or No From code behind?

If you assign a hiddenField's (input element of type hidden) value via Javascript, and this hiddenField control is within the <form> element, then yes, you would be able to read the value from code-behind once the postback occurs.

Why are you creating the javascript code in code-behind. Just include the javascript code in your aspx page and you are done. For the hiddenField control, set the ClientIDMode to static so you already know what the ID is of this input element.

Because i trying to make a function inside a .cs class file..
and this .cs class's functions/methods is centralized to all pages, thus those pages need this methods i just call this .cs functions instead of copy and paste code. :)

I am using AjaxConfirmExtender, it returning the same result as well as i expected. Thanks for the great advise :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.