在 VB.Net 中使用 Javascript 警报。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22245627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:59:58  来源:igfitidea点击:

Using a Javascript alert in VB.Net.

javascriptjqueryasp.netsql-servervb.net

提问by Kallumasaurus

Basically I am looking to you a Javascript alert in my code because I am displaying this web application in a mobile browser ( off a Tablet ) and well the Normal...

基本上,我希望在我的代码中向您发送 Javascript 警报,因为我正在移动浏览器(关闭平板电脑)中显示此 Web 应用程序,并且正常...

Try

Try

Catch ex As Exception

Catch ex As Exception

Messagebox.Show("Insert Text Here")

Messagebox.Show("Insert Text Here")

End Try

End Try

Doesn't work in a mobile browser so I've been told to use a Javascript Alertin which I have no idea where to start on this , yes I have used a little JS in the past & still trying to learn it but never come across using a alertSo here is my code below in which I need to place this alert. Any guidance will be rewarded in answer if it guides me to my end goal.

在移动浏览器中不起作用,所以我被告知使用一个Javascript Alert我不知道从哪里开始的,是的,我过去使用过一些 JS 并且仍在尝试学习它但从未遇到使用aalert所以这是我下面的代码,我需要在其中放置它alert。如果任何指导能引导我实现最终目标,那么任何指导都会得到回报。

  Protected Sub OkBtn_Click(sender As Object, e As System.EventArgs) Handles OkBtn.Click
        Dim ThisDay As Date = Date.Today
        Dim ThisUser As String
        ThisUser = Request.QueryString("")
        If ThisUser = "" Then
            ThisUser = "Chris Heywood"
    End If
    Dim transType As String
    transType = Request.QueryString("")
    If transType = "" Then
        transType = "Fire"
    End If
        connection.Open()
    command = New SqlCommand("Insert Into FireTest([Date],[Type],[Comments],[Completed By],[Trans Type]) Values(@Date,@Type,@Comments,@CompletedBy, @TransType)", connection)
    command.Parameters.AddWithValue("@Date", ThisDay)
    command.Parameters.AddWithValue("@Type", dropdownList1.SelectedValue)
    command.Parameters.AddWithValue("@Comments", TextBox1.Text)
    command.Parameters.AddWithValue("@CompletedBy", ThisUser)
    command.Parameters.AddWithValue("@TransType", transType)
    command.ExecuteNonQuery()
    connection.Close()
    Response.Redirect("~/Production/Navigator.aspx")
End Sub

So Basically this alertshould be active if there is a error in inserting the information into SQL ( If there is nothing in the field ).

所以基本上,alert如果在将信息插入 SQL 时出错(如果字段中没有任何内容),这应该是活动的。

Happy hunting!

狩猎快乐!

P.S , Would Jquery be viable for this as it's easy to type rather than JS?

PS,Jquery 是否可行,因为它比 JS 更容易输入?

回答by freefaller

You need to understand the difference between server-side code (what you have provided in your question, and is processed on the server) and client-side code (which is what the browser receives from the server and processes on the users machine).

您需要了解服务器端代码(您在问题中提供的内容,并在服务器上处理)和客户端代码(浏览器从服务器接收并在用户机器上处理的内容)之间的区别。

The javascript alert(or window.alert) is a way of putting up a message box with an OKbutton. If you want a "yes/no" type response, you can use a confirm(or window.confirm) which will return trueif OKis selected and falseif Cancelis selected (or Escapepressed).

javascript alert(或window.alert)是一种放置带有OK按钮的消息框的方法。如果你想要一个“是/否”类型的响应,你可以使用confirm(或window.confirm),true如果OK被选中,false如果Cancel被选中(或Escape按下),它将返回。

One of the fastest ways of getting what you want it to register script...

获取您想要的内容以注册脚本的最快方法之一...

Try
   ...  
Catch ex As Exception
   Dim myScript as String = "window.alert('There is a problem');"
   ClientScript.RegisterStartupScript(Me.GetType(), "myScript", myScript, True)
End Try

For more information on this function, see the MSDN entry

有关此功能的更多信息,请参阅MSDN 条目