CooperTupelo
asked on
confirmation box with return answer driving vb code
I have an application where I have added many rows of data in code behind to a web application. I want to be able when one of the textbox is changed to make sure the value does not exceed 15 without the users approval. I want to popup a confirmation box that says are you sure you want the value to exceed 15 and then if the answer is yes proceed, if they anser no exit the sub. I have hidden values to correspond with each value to reset the textbox if the user clicks Cancel.
This is the on change event;
Private Sub CompressedSectionWidth_Tex tChanged(B yVal sender As Object, ByVal e As EventArgs)
Dim strSQL As String
Dim txtSKU As TextBox = New TextBox
Dim txtCenterStackQuantity As TextBox = New TextBox
Dim txtMaxPalletStack As TextBox = New TextBox
Dim txtPalletType As TextBox = New TextBox
Dim txtStacksPerPallet As TextBox = New TextBox
Dim txtMaxGantryStack As TextBox = New TextBox
Dim txtPalletQuantity As TextBox = New TextBox
Dim txtUninflatedOuterDiameter As TextBox = New TextBox
Dim txtUninflatedSectionWidth As TextBox = New TextBox
Dim txtCompressedSectionWidth As TextBox = New TextBox
Dim txtTS_Compressed_Section_W idth As TextBox = New TextBox
Dim txt As TextBox = New TextBox
Dim txtBoxID As Integer = Nothing
Dim txtConfirm As String
'Equate the textbox to the sender object which is our TextBox
txt = sender
'This gets the number i.e I
Try
txtBoxID = Microsoft.VisualBasic.Stri ngs.Mid(tx t.ID.ToStr ing, txt.ID.Length - 5, txt.ID.Length)
Catch ex As Exception
Try
txtBoxID = Microsoft.VisualBasic.Stri ngs.Mid(tx t.ID.ToStr ing, txt.ID.Length - 4, txt.ID.Length)
Catch
Try
txtBoxID = Microsoft.VisualBasic.Stri ngs.Mid(tx t.ID.ToStr ing, txt.ID.Length - 3, txt.ID.Length)
Catch
Try
txtBoxID = Microsoft.VisualBasic.Stri ngs.Mid(tx t.ID.ToStr ing, txt.ID.Length - 2, txt.ID.Length)
Catch
Try
txtBoxID = Microsoft.VisualBasic.Stri ngs.Mid(tx t.ID.ToStr ing, txt.ID.Length - 1, txt.ID.Length)
Catch
txtBoxID = Microsoft.VisualBasic.Stri ngs.Mid(tx t.ID.ToStr ing, txt.ID.Length, txt.ID.Length)
End Try
End Try
End Try
End Try
End Try
'Find our textboxes
txtSKU = Me.FindControl("txtSKU" & txtBoxID)
txtCenterStackQuantity = Me.FindControl("txtCenterS tackQuanti ty" & txtBoxID)
txtMaxPalletStack = Me.FindControl("txtMaxPall etStack" & txtBoxID)
txtPalletType = Me.FindControl("txtPalletT ype" & txtBoxID)
txtStacksPerPallet = Me.FindControl("txtStacksP erPallet" & txtBoxID)
txtMaxGantryStack = Me.FindControl("txtMaxGant ryStack" & txtBoxID)
txtPalletQuantity = Me.FindControl("txtPalletQ uantity" & txtBoxID)
txtUninflatedOuterDiameter = Me.FindControl("txtUninfla tedOuterDi ameter" & txtBoxID)
txtUninflatedSectionWidth = Me.FindControl("txtUninfla tedSection Width" & txtBoxID)
txtCompressedSectionWidth = Me.FindControl("txtCompres sedSection Width" & txtBoxID)
txtTS_Compressed_Section_W idth = Me.FindControl("txtTS_Comp ressed_Sec tion_Width " & txtBoxID)
__________________________ _____
''Following code executed if user clicks YES
__________________________ ______
strSQL = "APP_COMPRESSED_SEC_WIDTH_ UPD.UPD_CO MPRESSED_S ECTION_WID TH"
m_objCompressed_Section_Wi dth = New Compressed_Section_Width_D ALC
m_objCompressed_Section_Wi dth.APP_CO MPRESSED_S EC_WIDTH_U PD(txtSKU. Text, _
txtCompressedSectionWidth. Text, strSQL, "prmCSW")
__________________________ __________ ___
''Skip to here is user clicks no or cancel
__________________________ __________ ___
txtCompressedSectionWidth. Text = txtHiddenCompressedSection Width.Text
Session("Changed") = True
Session("SKU") = txtSKU.Text
Server.Transfer("DataForm. aspx")
End Sub
This is the on change event;
Private Sub CompressedSectionWidth_Tex
Dim strSQL As String
Dim txtSKU As TextBox = New TextBox
Dim txtCenterStackQuantity As TextBox = New TextBox
Dim txtMaxPalletStack As TextBox = New TextBox
Dim txtPalletType As TextBox = New TextBox
Dim txtStacksPerPallet As TextBox = New TextBox
Dim txtMaxGantryStack As TextBox = New TextBox
Dim txtPalletQuantity As TextBox = New TextBox
Dim txtUninflatedOuterDiameter
Dim txtUninflatedSectionWidth As TextBox = New TextBox
Dim txtCompressedSectionWidth As TextBox = New TextBox
Dim txtTS_Compressed_Section_W
Dim txt As TextBox = New TextBox
Dim txtBoxID As Integer = Nothing
Dim txtConfirm As String
'Equate the textbox to the sender object which is our TextBox
txt = sender
'This gets the number i.e I
Try
txtBoxID = Microsoft.VisualBasic.Stri
Catch ex As Exception
Try
txtBoxID = Microsoft.VisualBasic.Stri
Catch
Try
txtBoxID = Microsoft.VisualBasic.Stri
Catch
Try
txtBoxID = Microsoft.VisualBasic.Stri
Catch
Try
txtBoxID = Microsoft.VisualBasic.Stri
Catch
txtBoxID = Microsoft.VisualBasic.Stri
End Try
End Try
End Try
End Try
End Try
'Find our textboxes
txtSKU = Me.FindControl("txtSKU" & txtBoxID)
txtCenterStackQuantity = Me.FindControl("txtCenterS
txtMaxPalletStack = Me.FindControl("txtMaxPall
txtPalletType = Me.FindControl("txtPalletT
txtStacksPerPallet = Me.FindControl("txtStacksP
txtMaxGantryStack = Me.FindControl("txtMaxGant
txtPalletQuantity = Me.FindControl("txtPalletQ
txtUninflatedOuterDiameter
txtUninflatedSectionWidth = Me.FindControl("txtUninfla
txtCompressedSectionWidth = Me.FindControl("txtCompres
txtTS_Compressed_Section_W
__________________________
''Following code executed if user clicks YES
__________________________
strSQL = "APP_COMPRESSED_SEC_WIDTH_
m_objCompressed_Section_Wi
m_objCompressed_Section_Wi
txtCompressedSectionWidth.
__________________________
''Skip to here is user clicks no or cancel
__________________________
txtCompressedSectionWidth.
Session("Changed") = True
Session("SKU") = txtSKU.Text
Server.Transfer("DataForm.
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I know if I put something like below(something somewhere off experts exchange searching and searching) in the Load Routine.
A confirmation box will pop up when I change the compressed section width text box.
But no matter if the user checks OK or Cancel nothing happens, which is useless.
If I leave the
AddHandler ctlCompressedSectionWidth. TextChange d, AddressOf CompressedSectionWidth_Tex tChanged
in the Load routine then no matter if the user checks OK or Cancel the record is changed anyway, which is also useless.
I have no idea how to get the value of the confirmation box back to the routine to control what happens nnext.
If I use a label (which I'm happy to use anything I can capture the users response from) how can I let the user decide wether to accept a value over 15 or return it to the original value?
__________________________ __________ __________ __________ __________ __________ ________
If Not Page.IsClientScriptBlockRe gistered(" doConfirm" ) Then
Dim buffScriptString As String
buffScriptString = "<script language='javascript'>" + vbCrLf + _
"<!-- " + vbCrLf + _
"function __doConfirm(ctlCompressedS ectionWidt h) { " + vbCrLf + _
"if (confirm('Click to confirm message')) { " + vbCrLf + _
" return true; " + vbCrLf + _
"} return false; } " + vbCrLf + _
"--> " + vbCrLf + _
"</script>"
Page.RegisterClientScriptB lock("doCo nfirm", buffScriptString)
End If
ctlCompressedSectionWidth. Attributes .Add("onch ange", "return __doConfirm(this);")
A confirmation box will pop up when I change the compressed section width text box.
But no matter if the user checks OK or Cancel nothing happens, which is useless.
If I leave the
AddHandler ctlCompressedSectionWidth.
in the Load routine then no matter if the user checks OK or Cancel the record is changed anyway, which is also useless.
I have no idea how to get the value of the confirmation box back to the routine to control what happens nnext.
If I use a label (which I'm happy to use anything I can capture the users response from) how can I let the user decide wether to accept a value over 15 or return it to the original value?
__________________________
If Not Page.IsClientScriptBlockRe
Dim buffScriptString As String
buffScriptString = "<script language='javascript'>" + vbCrLf + _
"<!-- " + vbCrLf + _
"function __doConfirm(ctlCompressedS
"if (confirm('Click to confirm message')) { " + vbCrLf + _
" return true; " + vbCrLf + _
"} return false; } " + vbCrLf + _
"--> " + vbCrLf + _
"</script>"
Page.RegisterClientScriptB
End If
ctlCompressedSectionWidth.
ASKER
I have converted a copy of this project over to ASP.NET 2005, in case there is someway to accomplish what I need using it that was not available iin ASP.NET 2003.
ASKER
I will go ahead and accept this answer though it does not allow me to put a confirmation box on the screen as I would like. No one else has answered follow up comments. I created instead a panel with a yes and no button on it that appears and disappears based on the value of some session variables and a lot of if statements. ASP.NET just isn't very programmer friendly in my opinion.
ASKER
I created a panel with a yes and no button on it that appears and disappears based on the value of some session variables and a lot of if statements. Something others may want to consider.
use the clientside onClick event of the button to call the javascript and get the prompt.
Have the javascript return a boolean value. If it is true, it will continue submitting the page, if false, it will not submit the page.