简体   繁体   English

在 VB.Net 中使用 Javascript 警报

[英]Using a Javascript alert in VB.Net

Basically I am looking to create 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
    ' ...
Catch ex As Exception
    Messagebox.Show("Insert Text Here")
End Try

doesn't work in a mobile browser, so I've been told to use a JavaScript alert but I have no idea where to start on this, yes I have used a little JS in the past and still trying to learn it but never came across using an alert .在移动浏览器中不起作用,所以我被告知要使用 JavaScript alert但我不知道从哪里开始,是的,我过去使用过一些 JS 并且仍在尝试学习它,但从未学习过跨越使用alert So here is my code below, in which I need to place this alert .所以这是我下面的代码,我需要在其中放置这个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 alert should be active if there is a error in inserting the information into the database (if there is nothing in the field).因此,如果将信息插入数据库时​​出现错误(如果该字段中没有任何内容),则基本上该alert应该处于活动状态。

PS Would jQuery be viable for this, as it's easy to type, rather than JS? PS jQuery 是否可行,因为它很容易输入,而不是 JS?

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 OK button. javascript alert (或window.alert )是一种放置带有OK按钮的消息框的方法。 If you want a "yes/no" type response, you can use a confirm (or window.confirm ) which will return true if OK is selected and false if Cancel is selected (or Escape pressed).如果您想要“是/否”类型的响应,您可以使用confirm (或window.confirm ),如果选择了OK则返回true如果选择取消(或按下Escape )则返回false

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 条目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM