我正在尝试在用户提交表单时添加提醒。我希望它只在提交成功时显示警告,否则我只是在提交按钮上附加一个javascript警报。我按照这里建议的方法:
但警报部分无效。我尝试将警报代码放在Page_Load中并且它有效,但是当我将它放在按钮单击处理程序中时,我没有收到任何警报。
Public Sub Send_Data(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewsletter.Click
Dim sFName, sLName As String
Dim sEmail As String
Dim clsUser As New clsLogin
Dim iConfirm As Integer
sEmail = email.Text
If sEmail = "" Then Exit Sub
Try
If clsUser.Check_Cookie = False Then
iConfirm = clsUser.Create_Acct("", "", sEmail, "", iType)
End If
clsUser.Add_AvailLog(0, iType, iChat)
Catch
End Try
'start JK
Dim blog As Destinations.GetBlog
Dim TargetURL As String
TargetURL = "http://wimco.us8.list-manage.com/subscribe/post?u=fe50a5183f6f54bb70a7005e3&id=b2e21157fc"
Dim html As String
Dim PostData As String
PostData = "&EMAIL=" & sEmail & "&b_fe50a5183f6f54bb70a7005e3_b2e21157fc=&subscribe=Subscribe"
html = blog.PostData(TargetURL, PostData)
email.Text = ""
' This is the alert section
Dim message As String = "Order Placed Successfully."
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append("alert('")
sb.Append(message)
sb.Append("');")
sb.Append("</script>")
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
End Sub
答案 0 :(得分:1)
我一直在做类似的事情,你的代码看起来还不错。
您是否尝试调试代码并确保代码到达调用RegisterClientScriptBlock的Send_Data函数的末尾?
我感觉它停在了if sEmail =“”然后退出Sub。
答案 1 :(得分:0)
您必须将警报放在提交的页面后显示的页面上。