【发布时间】:2017-07-26 18:03:22
【问题描述】:
我在 ASP/VB.net 中遇到了一个奇怪的行为。 我试图从后面的 VB 代码中调用 JS,但什么也没发生。我在几个页面上使用了类似(几乎相同)的方法,效果很好。但是,它不适用于这个。 我试图问用户一个是/否类型的问题。结果存储到一个名为confirm_value的隐藏字段中,然后如果用户回答“是/继续”,JS会再次单击按钮
<asp:HiddenField runat="server" id ="confirm_value"/>
但是 JS 从不触发。我什至尝试像注释代码一样进行简单的“Hi There”警报调用,但它也不起作用。 什么可以阻止 JS 代码触发?
VB 代码:
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代码:
<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>
【问题讨论】:
标签: javascript asp.net vb.net