How to display a confirmation for one of the checkboxes if the user changed the status
-
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.
-
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.
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. -
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.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
-
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
Okay, how about this:
Private boolChanged As Boolean
Private Sub Form_Load()
boolChanged = False
End SubPrivate 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 SubPrivate Sub Check1_Click()
boolChanged = True
End SubPrivate Sub Check2_Click()
boolChanged = True
End Sub -
Okay, how about this:
Private boolChanged As Boolean
Private Sub Form_Load()
boolChanged = False
End SubPrivate 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 SubPrivate Sub Check1_Click()
boolChanged = True
End SubPrivate Sub Check2_Click()
boolChanged = True
End Sub -
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
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. -
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.