在VB中转换asp.net中的messageBox
我有以下创建消息框的函数在VB中转换asp.net中的messageBox,asp.net,vb.net,Asp.net,Vb.net,我有以下创建消息框的函数 Function Question() As Boolean If MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Question") = MsgBoxResult.Yes Then RunSubRoutine() txtbox.focus Return True Else Return False
Function Question() As Boolean
If MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Question") = MsgBoxResult.Yes Then
RunSubRoutine()
txtbox.focus
Return True
Else
Return False
End If
End Function
我如何更改它,使它在ASP.Net中工作相同,因为我需要它返回一个值 没有这样的直接选择来实现这一点。
ASP.NET在加载页面后释放进程。您可以使用ajax或事件处理发送请求 asp.net中没有messagebox这样的东西。你可以做这个选择
if(confirm('Are you sure?')){
// do this
}
else{
// do something else
}
您不能这样提示用户,因为ASP.NET是服务器端语言。您需要使用javascript(或JQuery以获得更高级的弹出窗口)来完成以下操作:
<script>
function Question() {
if (confirm('Are you sure?')) {
document.getElementById("your_textbox_id").focus()
}
}
</script>
<script>
function Question() {
if (confirm('Are you sure?')) {
window.location.href = "test.aspx?confirm=yes";
}
}
</script>
或者,您可以通过发出AJAX请求将javascript返回的结果发布到服务器,这更复杂,但不需要重新加载页面…您的意思是在asp.net中显示警报?一个确认框。请参阅我的帖子,这是一个javascript。您需要将其附加到页面上。如果我想调用声明中的另一个子例程,我该怎么办?
If Request.QueryString("confirm") = "yes" then
//call your asp.net routine here
End If