Solved

confirmation box with return answer driving vb code

Posted on 2008-10-27
6
542 Views
Last Modified: 2013-11-07
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_TextChanged(ByVal 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_Width 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.Strings.Mid(txt.ID.ToString, txt.ID.Length - 5, txt.ID.Length)
        Catch ex As Exception
            Try
                txtBoxID = Microsoft.VisualBasic.Strings.Mid(txt.ID.ToString, txt.ID.Length - 4, txt.ID.Length)
            Catch
                Try
                    txtBoxID = Microsoft.VisualBasic.Strings.Mid(txt.ID.ToString, txt.ID.Length - 3, txt.ID.Length)
                Catch
                    Try
                        txtBoxID = Microsoft.VisualBasic.Strings.Mid(txt.ID.ToString, txt.ID.Length - 2, txt.ID.Length)
                    Catch
                        Try
                            txtBoxID = Microsoft.VisualBasic.Strings.Mid(txt.ID.ToString, txt.ID.Length - 1, txt.ID.Length)
                        Catch
                            txtBoxID = Microsoft.VisualBasic.Strings.Mid(txt.ID.ToString, 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("txtCenterStackQuantity" & txtBoxID)
        txtMaxPalletStack = Me.FindControl("txtMaxPalletStack" & txtBoxID)
        txtPalletType = Me.FindControl("txtPalletType" & txtBoxID)
        txtStacksPerPallet = Me.FindControl("txtStacksPerPallet" & txtBoxID)
        txtMaxGantryStack = Me.FindControl("txtMaxGantryStack" & txtBoxID)
        txtPalletQuantity = Me.FindControl("txtPalletQuantity" & txtBoxID)
        txtUninflatedOuterDiameter = Me.FindControl("txtUninflatedOuterDiameter" & txtBoxID)
        txtUninflatedSectionWidth = Me.FindControl("txtUninflatedSectionWidth" & txtBoxID)
        txtCompressedSectionWidth = Me.FindControl("txtCompressedSectionWidth" & txtBoxID)
        txtTS_Compressed_Section_Width = Me.FindControl("txtTS_Compressed_Section_Width" & txtBoxID)

_______________________________
''Following code executed if user clicks YES
________________________________

        strSQL = "APP_COMPRESSED_SEC_WIDTH_UPD.UPD_COMPRESSED_SECTION_WIDTH"

            m_objCompressed_Section_Width = New Compressed_Section_Width_DALC
            m_objCompressed_Section_Width.APP_COMPRESSED_SEC_WIDTH_UPD(txtSKU.Text,  _      
                                                                          txtCompressedSectionWidth.Text, strSQL, "prmCSW")
_______________________________________
''Skip to here is user clicks no or cancel
_______________________________________

            txtCompressedSectionWidth.Text = txtHiddenCompressedSectionWidth.Text
            Session("Changed") = True
            Session("SKU") = txtSKU.Text
            Server.Transfer("DataForm.aspx")
    End Sub
0
Comment
Question by:CooperTupelo
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 22817023
you will want to create a javascript function that will handle your scenario.

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.

0
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 500 total points
ID: 22817047
btw, you are not able to call a confirm or message box in codebehind of a web page.

alternatively, you can have an error message display in a label on the page and stop processing so that the page remains as when they submitted it. But you will not be able to get the confirm popup unless you use javascript.
0
 

Author Comment

by:CooperTupelo
ID: 22821255
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.TextChanged, AddressOf CompressedSectionWidth_TextChanged
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.IsClientScriptBlockRegistered("doConfirm") Then
            Dim buffScriptString As String
            buffScriptString = "<script language='javascript'>" + vbCrLf + _
               "<!-- " + vbCrLf + _
               "function __doConfirm(ctlCompressedSectionWidth) { " + vbCrLf + _
               "if (confirm('Click to confirm message')) { " + vbCrLf + _
               " return true; " + vbCrLf + _
               "} return false; } " + vbCrLf + _
               "--> " + vbCrLf + _
               "</script>"

            Page.RegisterClientScriptBlock("doConfirm", buffScriptString)
        End If

ctlCompressedSectionWidth.Attributes.Add("onchange", "return __doConfirm(this);")
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:CooperTupelo
ID: 22832301
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.
0
 

Author Closing Comment

by:CooperTupelo
ID: 31513095
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.
0
 

Author Comment

by:CooperTupelo
ID: 22876828
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.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 32
bound data table problem 2 33
Why do I get the message "Message has been thrown by target of an invocation"? 22 53
Where is this file? 3 26
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question