0

I'm expriencing an odd behavior in ASP/VB.net. I am attempting to call a JS from the VB code behind, but nothing is happening. I use a similar(almost identical) method on several pages with great results. However, it doesn't work on this one. I am trying to ask the user a yes/no type question. The result is stored to a hidden field named confirm_value, then the JS clicks the button again if the user ansers "yes/continue"

<asp:HiddenField  runat="server" id ="confirm_value"/>

However the JS never fires. I even tried making a simple "Hi There" alert call, as in the commented code, which did not work either. What could prevent the JS code from firing?

VB Code:

If -1000 < RadNumericTextBox1.Text Then
        If confirm_value.Value <> "Yes" Then
            Dim cs As ClientScriptManager = Page.ClientScript
            ' Check to see if the startup script is already registered.
            If (Not cs.IsStartupScriptRegistered(Me.GetType(), "ConfirmScriptRXOrder")) Then
                Dim cstext1 As String = "Confirm('This item has less in stock than your order. Do you want to order it anyway?');"
                'Dim cstext1 As String = "alert('Hi there!');"
                cs.RegisterStartupScript(Me.GetType(), "ConfirmScriptRXOrder", cstext1, True)
            End If
            'return here, JS will re-click submit button after okaying the message,.
            Return
        Else
            confirm_value.Value = "No"
            Mycart(ddCyl.SelectedValue.ToString, ddSph.SelectedItem.Text, ddCyl.SelectedItem.Text, RadNumericTextBox1.Text, tbtray.Text)

            RadGrid1.DataBind()
        End If
    End If

JS Code:

<script type = "text/javascript">
    function Confirm(message) {
        if (confirm(message)) {
            var x = document.getElementById('<%= confirm_value.ClientID%>');
            x.value = 'Yes';
            document.getElementById('<%=btnOrder.ClientID%>').click();
        } else {
            var x = document.getElementById('<%= confirm_value.ClientID%>');
            x.value = 'No';
        }
    }
</script>

2 Answers 2

1

I hate to answer my own question, but the solution was not obvious in what I originally posted, and had nothing to do with the actual code I posted. I stripped the page down to the submit button, JS, and VB call to it. It worked! I started adding back code until it broke. The issue was the button was inside an asp:updatepanel . I moved the button outside the update panel and it worked as I wanted! Didn't look quite as visually balanced, but... So if you ever have a situation like this, remember this post!

Sign up to request clarification or add additional context in comments.

Comments

0

I'm no expert in java...

but shouldn't your java function be called "ConfirmScriptRXOrder" instead of "Confirm"?

2 Comments

That is a unique name for registering the call to script that you are in essence creating. "Confirm(blah, blah) " I did figure out the situation which I will post so everyone, who has this problem can learn.
Well done, so you resolved the issue and posted your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.