vb.net 客户端警报背后的代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18217073/
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
Code Behind Client Side Alert
提问by Kathy
I previous asked for assistance but don't think I ask the right question. I am new to coding & have a web app with a form on it which has a yes/no dropdown & a textbox after for a reason. I managed to write the code behind for a msgbox but I need it on the client side. I know it's not nearly as complicated as I thihk. This is the code behind I used for the server side msgbox:
我之前曾寻求帮助,但认为我提出的问题不正确。我是编码新手,并且有一个带有表单的网络应用程序,出于某种原因,它有一个是/否下拉列表和一个文本框。我设法为 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
Can someone, ANYONE please give me some guidance of how I would write this for a client side alert? Preferably in code behind.
有人,任何人都可以给我一些关于如何为客户端警报编写此内容的指导吗?最好在后面的代码中。
回答by Adil Al-Hilali
Dim message As String = "If Critical, you MUST provide a reason."
Dim script As String = "<script type='text/javascript'> alert('" + message + "');</script>"
correction for the Above will be as this
上面的更正将是这样
ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertBox", script)
Dont forget the single qouts at the alert code
不要忘记警报代码处的单个 qouts
回答by Malachi
this is one of the answers found on the link given above. of course you will have to adapt it to your code a little bit.
这是在上面给出的链接中找到的答案之一。当然,您必须稍微调整一下以适应您的代码。
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)
I have not tested this code so I don't know that it works the way you intend it to, please test
我没有测试过这段代码,所以我不知道它是否按照你的预期工作,请测试

