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>