【问题标题】:Code Behind Client Side Alert客户端警报背后的代码
【发布时间】:2013-08-15 12:58:00
【问题描述】:

我之前曾寻求帮助,但我认为我问的问题不正确。我是编码新手,并且有一个 Web 应用程序,上面有一个表单,它有一个是/否下拉列表和一个文本框,这是有原因的。我设法为 msgbox 编写了代码,但我在客户端需要它。我知道这并不像我想象的那么复杂。这是我用于服务器端 msgbox 的代码:

Protected Sub SubmitButton_Click(sender As Object, e As Event Args) Handles SubmitButton.Click
If CriticalList.Text = "Yes" THEN
 If TextBox13.Text <> "" THEN
   SqlDataSource1.Insert()
 Response.Redirect("FormsReport.aspx")
ELSE
  MsgBox("If critical, you MUST provide a reason.")
 End IF
ELSE
   SqlDataSource1.Insert()
  Response.Redirect("FormsReport.aspx")
End IF
End SUB

谁能给我一些指导,告诉我如何为客户端警报编写这个?最好在代码后面。

【问题讨论】:

标签: vb.net visual-studio-2010 client-side code-behind


【解决方案1】:

http://social.msdn.microsoft.com/Forums/en-US/7d156d49-ea9a-4f58-a17f-228c9470ee7a/display-a-message-box-in-a-vbnet-web-application

这是在上面给出的链接中找到的答案之一。当然,您将不得不稍微调整它以适应您的代码。

Dim message As String = "If Critical, you MUST provide a reason."
Dim script As String = "<script type='text/javascript'> alert(" + message + ");</script>"

ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertBox", script)

我没有测试过这段代码,所以我不知道它是否按照你想要的方式工作,请测试

【讨论】:

    【解决方案2】:
    Dim message As String = "If Critical, you MUST provide a reason."
    Dim script As String = "<script type='text/javascript'> alert('" + message + "');</script>"
    

    对以上内容的更正如下

    ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertBox", script)
    

    不要忘记警报代码中的单个 qouts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多