在VB.Net中使用Javascript警报 [英] Using a Javascript alert in VB.Net

查看:75
本文介绍了在VB.Net中使用Javascript警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我希望在代码中创建JavaScript警报,因为我正在移动浏览器(平板电脑以外)上显示此Web应用程序,而且正常情况下...

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...

Try
    ' ...
Catch ex As Exception
    Messagebox.Show("Insert Text Here")
End Try

在移动浏览器中不起作用,所以有人告诉我要使用JavaScript alert ,但是我不知道从哪里开始,是的,我在其中使用了一些JS.过去并且仍在尝试学习它,但是从未使用过 alert 遇到过.所以这是下面的代码,我需要在其中放置此 alert .

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. So here is my code below, in which I need to place this 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

因此,基本上,如果在将信息插入数据库时​​出错(如果字段中没有任何内容),则此 alert 应该是活动的.

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).

P.S.jQuery是否可以做到这一点,因为它很容易键入,而不是JS?

P.S. Would jQuery be viable for this, as it's easy to type, rather than 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).

javascript alert (或 window.alert )是一种使用 OK 按钮放置消息框的方法.如果您想要是/否"类型的响应,则可以使用 confirm (或 window.confirm ),如果<如果选择了取消(或按下了 Escape ),则选择kbd>确定" ,并选择 false .

The javascript alert (or window.alert) is a way of putting up a message box with an OK button. 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).

获取所需内容以注册脚本的最快方法之一...

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

这篇关于在VB.Net中使用Javascript警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆