Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to display a confirmation for one of the checkboxes if the user changed the status

How to display a confirmation for one of the checkboxes if the user changed the status

Scheduled Pinned Locked Moved Visual Basic
helptutoriallearning
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tram88
    wrote on last edited by
    #1

    Dear All, I am a beginner of VB and I am trying to create a Confirmation Message for a particular checkbox. The scenario is that: suppose I have two (2)checkboxes and one Submit button. If I just want to display a confirmation for the checkbox #1 only. The user changes the status on checkbox 1 (on/off), then click on the Submit button, this confirmation will display. Would you please help me out. I would appreciate it.

    K 1 Reply Last reply
    0
    • T Tram88

      Dear All, I am a beginner of VB and I am trying to create a Confirmation Message for a particular checkbox. The scenario is that: suppose I have two (2)checkboxes and one Submit button. If I just want to display a confirmation for the checkbox #1 only. The user changes the status on checkbox 1 (on/off), then click on the Submit button, this confirmation will display. Would you please help me out. I would appreciate it.

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      I'm not sure I understand the question completely. If you want to always display a confirmation message if it is checked, that's pretty straight forward. If you want to display a confirmation message if the value has changed you will have to create a variable to record if it has changed or not. I would use a boolean value which is originally set to false and is set to true only in the CheckChanged event of the checkbox in question. The code for the confirmation box would look something like this: Dim result As New DialogResult result = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) Select Case result Case Windows.Forms.DialogResult.Yes 'Code for Yes action Case Windows.Forms.DialogResult.No 'Code for No action End Select Of course, you have a lot of options here. Use the intellisense help to see the different combinations of buttons and other options that you can use. This code was written in Visual Studio 2005, but if you use a different version it should still be very similar. Hope this helps.

      T 1 Reply Last reply
      0
      • K Kschuler

        I'm not sure I understand the question completely. If you want to always display a confirmation message if it is checked, that's pretty straight forward. If you want to display a confirmation message if the value has changed you will have to create a variable to record if it has changed or not. I would use a boolean value which is originally set to false and is set to true only in the CheckChanged event of the checkbox in question. The code for the confirmation box would look something like this: Dim result As New DialogResult result = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) Select Case result Case Windows.Forms.DialogResult.Yes 'Code for Yes action Case Windows.Forms.DialogResult.No 'Code for No action End Select Of course, you have a lot of options here. Use the intellisense help to see the different combinations of buttons and other options that you can use. This code was written in Visual Studio 2005, but if you use a different version it should still be very similar. Hope this helps.

        T Offline
        T Offline
        Tram88
        wrote on last edited by
        #3

        Dear Kschuler, I am so glad to receive a message from you. However, let me clear my problem so that you can get it fully. Suppose a user is modifing a form that have 2 checkboxes (checkbox1 and checkbox2) and 1 submit button. If a user change (check or uncheck) the checkbox1, then a confirmation will display. That is my problem, and I am using VB6. Would you please help me out. I would appreciate your help very much, Tram88

        K 1 Reply Last reply
        0
        • T Tram88

          Dear Kschuler, I am so glad to receive a message from you. However, let me clear my problem so that you can get it fully. Suppose a user is modifing a form that have 2 checkboxes (checkbox1 and checkbox2) and 1 submit button. If a user change (check or uncheck) the checkbox1, then a confirmation will display. That is my problem, and I am using VB6. Would you please help me out. I would appreciate your help very much, Tram88

          K Offline
          K Offline
          Kschuler
          wrote on last edited by
          #4

          Okay, how about this:

          Private boolChanged As Boolean

          Private Sub Form_Load()
          boolChanged = False
          End Sub

          Private Sub btnSubmit_Click()
          Dim result As VbMsgBoxResult
          If boolChanged = True Then
          result = MsgBox("Are you sure?", vbYesNo, "Confirm")
          Select Case result
          Case VbMsgBoxResult.vbYes
          'Code if user selects Yes
          Case VbMsgBoxResult.vbNo
          'Code if user selects No
          End Select
          Exit Sub
          End If
          'Code if no changes were made to check boxes
          End Sub

          Private Sub Check1_Click()
          boolChanged = True
          End Sub

          Private Sub Check2_Click()
          boolChanged = True
          End Sub

          T 1 Reply Last reply
          0
          • K Kschuler

            Okay, how about this:

            Private boolChanged As Boolean

            Private Sub Form_Load()
            boolChanged = False
            End Sub

            Private Sub btnSubmit_Click()
            Dim result As VbMsgBoxResult
            If boolChanged = True Then
            result = MsgBox("Are you sure?", vbYesNo, "Confirm")
            Select Case result
            Case VbMsgBoxResult.vbYes
            'Code if user selects Yes
            Case VbMsgBoxResult.vbNo
            'Code if user selects No
            End Select
            Exit Sub
            End If
            'Code if no changes were made to check boxes
            End Sub

            Private Sub Check1_Click()
            boolChanged = True
            End Sub

            Private Sub Check2_Click()
            boolChanged = True
            End Sub

            T Offline
            T Offline
            Tram88
            wrote on last edited by
            #5

            Dear Kschuler, Would you please confirm the codes that you wrote above, Should I put it into the .acsx or ascx.vb file? I would appreciate your potential helps very much. Tram88

            K 1 Reply Last reply
            0
            • T Tram88

              Dear Kschuler, Would you please confirm the codes that you wrote above, Should I put it into the .acsx or ascx.vb file? I would appreciate your potential helps very much. Tram88

              K Offline
              K Offline
              Kschuler
              wrote on last edited by
              #6

              Sorry...I assumed that you were creating a standard Windows Forms Application. This code will not work for a web project, and I am not sure I can help with a VB6 web project. I typically use VS2003, 2005. To perform your task in a web project I would probably set a hidden control on the page to record if the checkbox changes. Hidden controls look like this: <input id=hidChanged runat=server type=hidden /> (You will need another hidden control to store whether the user selected yes or no on the confirm if that determines which code to use later in the code behind) Then I would attach a javascript function to the button which would check the hidden variable and display a javacript confirm if needed. The javascript would look something like this: function CheckIfChanged() { //Check if checkbox has changed if (hidChanged.value <> "") { Result = confirm("Are you sure?"); if (Result) //The user selected "Yes" { form1.hidResult.value = "Y"; return true; }else{ //The user selected "Cancel" form1.hidResult.value = ""; return false; } } } The javascript would need to be connected to the button's on click event. Then of course, you need to set the hidden variable when ever a user clicks the checkbox. You can do this in code behind if it's okay to do a postback everytime the user clicks the checkbox, or you could use more javascript. I'm not sure how much of this applies to VB6, but I hope it will help you or at least give you some ideas to work from. Sorry I couldn't help you more.

              T 1 Reply Last reply
              0
              • K Kschuler

                Sorry...I assumed that you were creating a standard Windows Forms Application. This code will not work for a web project, and I am not sure I can help with a VB6 web project. I typically use VS2003, 2005. To perform your task in a web project I would probably set a hidden control on the page to record if the checkbox changes. Hidden controls look like this: <input id=hidChanged runat=server type=hidden /> (You will need another hidden control to store whether the user selected yes or no on the confirm if that determines which code to use later in the code behind) Then I would attach a javascript function to the button which would check the hidden variable and display a javacript confirm if needed. The javascript would look something like this: function CheckIfChanged() { //Check if checkbox has changed if (hidChanged.value <> "") { Result = confirm("Are you sure?"); if (Result) //The user selected "Yes" { form1.hidResult.value = "Y"; return true; }else{ //The user selected "Cancel" form1.hidResult.value = ""; return false; } } } The javascript would need to be connected to the button's on click event. Then of course, you need to set the hidden variable when ever a user clicks the checkbox. You can do this in code behind if it's okay to do a postback everytime the user clicks the checkbox, or you could use more javascript. I'm not sure how much of this applies to VB6, but I hope it will help you or at least give you some ideas to work from. Sorry I couldn't help you more.

                T Offline
                T Offline
                Tram88
                wrote on last edited by
                #7

                Dear Kschuler, Thank you very much for your potential helps. Tram88

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups