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

3
Contributors
7
Replies
17
Views
3 Years
Discussion Span
Last Post by gahhon
0

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.

0

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?

Edited by LastMitch

0

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

0

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.

0

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. :)

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.