Using a javascript confirm dialog.

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi,

Have a checkbox on my form, that has the postback enabled. What I would like to do is to display a confirm dialog asking the user are they sure they want to do this if the checkbox is checked true. If they click ok, then that no problem, however if they check cancel, I want to reset the checkbox back to its previous value. The approach that I am using to display message dialogues and confirm dialogues is as follows:
1. I add the following between the </form> and </body> tags
Code:
<script>
   <asp:Literal id="ltlAlert" runat="server" EnableViewState="False">
   </asp:Literal>
</script>

2. I add a withEvent declaration into the form design section of the code-behind page.
Code:
Protected WithEvents ltlAlert As System.Web.UI.WebControls.Literal

3. I then declare a method to handle the displaying of the message dialogues
Code:
Private Sub DisplayMessage(ByVal Message As String, Optional ByVal operator As Int16 = 1)
        Message = Message.Replace("'", "\'")
        Message = Message.Replace(Convert.ToChar(10), "\n")
        Message = Message.Replace(Convert.ToChar(13), "")
        ' Display as JavaScript alert
        Select Case operator
            Case 1
                ltlAlert.Text = "alert('" & Message & "')"
            Case 2
                ltlAlert.Text = "confirm('" & Message & "')"
        End Select
    End Sub

Any suggests??

Mike55.
 
Back
Top