.net 服务器端生成alert/confim 消息
来源:互联网 发布:qq群淘宝客优惠劵软件 编辑:程序博客网 时间:2024/04/30 02:22
一、 服务器端生成alert代码
message :消息内容
delay :延迟多长时间之后弹出消息框
FocusControl :关闭对话框之后焦点所在
AddScript :关闭对话框之后页面处罚的事件
IsUrl :关闭对话框之后转向的页面
Private Sub alert_client()Sub alert_client(ByVal message As String, ByVal delay As Integer, Optional ByVal FocusControl As Control = Nothing, Optional ByVal AddScript As String = Nothing, Optional ByVal IsUrl As Boolean = False)
Dim s As String, msg As String, MsgID As String
Dim sb As New System.Text.StringBuilder(message)
sb.Replace(vbCrLf, " ")
sb.Replace("'", "'")
sb.Replace("""", """")
msg = sb.ToString()
MsgID = UniqueMessageID()
s = "<script language='javascript'>" & vbCrLf
s += "function " & MsgID & "()" & vbCrLf
s += "{" & vbCrLf
s += "alert(""" & msg & """);" & vbCrLf
If Not FocusControl Is Nothing Then
s += "window.document.all['" & FocusControl.ClientID.ToString() & "'].focus();" & vbCrLf
If String.Compare(FocusControl.GetType.ToString, "System.Web.UI.WebControls.LinkButton") <> 0 Then
s += "window.document.all['" & FocusControl.ClientID.ToString() & "'].select();" & vbCrLf
End If
End If
If Not AddScript Is Nothing Then
If IsUrl Then
s += "window.location='" & AddScript & "';" & vbCrLf
Else
s += AddScript & vbCrLf
End If
End If
s += "}" & vbCrLf
s += "//-->" & vbCrLf
If delay = 0 Then
s += (MsgID & "();")
Else
s += "window.setTimeout(" & MsgID & "," & delay & ");" & vbCrLf
End If
s += "</script>" & vbCrLf
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), MsgID, s)
End Sub
Dim s As String, msg As String, MsgID As String
Dim sb As New System.Text.StringBuilder(message)
sb.Replace(vbCrLf, " ")
sb.Replace("'", "'")
sb.Replace("""", """")
msg = sb.ToString()
MsgID = UniqueMessageID()
s = "<script language='javascript'>" & vbCrLf
s += "function " & MsgID & "()" & vbCrLf
s += "{" & vbCrLf
s += "alert(""" & msg & """);" & vbCrLf
If Not FocusControl Is Nothing Then
s += "window.document.all['" & FocusControl.ClientID.ToString() & "'].focus();" & vbCrLf
If String.Compare(FocusControl.GetType.ToString, "System.Web.UI.WebControls.LinkButton") <> 0 Then
s += "window.document.all['" & FocusControl.ClientID.ToString() & "'].select();" & vbCrLf
End If
End If
If Not AddScript Is Nothing Then
If IsUrl Then
s += "window.location='" & AddScript & "';" & vbCrLf
Else
s += AddScript & vbCrLf
End If
End If
s += "}" & vbCrLf
s += "//-->" & vbCrLf
If delay = 0 Then
s += (MsgID & "();")
Else
s += "window.setTimeout(" & MsgID & "," & delay & ");" & vbCrLf
End If
s += "</script>" & vbCrLf
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), MsgID, s)
End Sub
二、服务器生成confim
message :消息内容
PostButton :关闭对话框之后触发的页面postback事件
AddScript :关闭对话框之后页面处罚的事件
Protected Function confirm()Function confirm(ByVal message As String, ByVal PostButton As Button, Optional ByVal AddScript As String = Nothing) As Boolean
Dim s As String, msg As String, MsgID As String
Dim sb As New System.Text.StringBuilder(message)
sb.Replace(vbCrLf, " ")
sb.Replace("'", "'")
sb.Replace("""", """")
msg = sb.ToString()
MsgID = UniqueMessageID()
s = "<script language='javascript'>" & vbCrLf
s += "<!--" & vbCrLf
s += "/* Client Alert Function" & vbCrLf
s += " CopyRight APJCorp.com" & vbCrLf
s += " Author:bss (Bianshusen@apjcorp.com)" & vbCrLf
s += " Date: 2004-8-24" & vbCrLf
s += "*/" & vbCrLf
s += "function " & MsgID & "()" & vbCrLf
s += "{" & vbCrLf
s += "var b;" & vbCrLf
s += "b=false;" & vbCrLf
s += "b=confirm(""" & msg & """);" & vbCrLf
s += "if (b==false)" & vbCrLf
s += "{" & vbCrLf
s += " return false;" & vbCrLf
s += "}" & vbCrLf
s += "else" & vbCrLf
s += "{" & vbCrLf
s += " __doPostBack('" & PostButton.UniqueID & "','') ;" & vbCrLf
s += "}" & vbCrLf
If Not AddScript Is Nothing Then
s += AddScript & vbCrLf
End If
s += "}" & vbCrLf
s += "//-->" & vbCrLf
s += "window.setTimeout(" & MsgID & ",10);" & vbCrLf
s += "</script>" & vbCrLf
'Me.Page.RegisterClientScriptBlock(MsgID, s)
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), MsgID, s)
Return True
End Function
Dim s As String, msg As String, MsgID As String
Dim sb As New System.Text.StringBuilder(message)
sb.Replace(vbCrLf, " ")
sb.Replace("'", "'")
sb.Replace("""", """")
msg = sb.ToString()
MsgID = UniqueMessageID()
s = "<script language='javascript'>" & vbCrLf
s += "<!--" & vbCrLf
s += "/* Client Alert Function" & vbCrLf
s += " CopyRight APJCorp.com" & vbCrLf
s += " Author:bss (Bianshusen@apjcorp.com)" & vbCrLf
s += " Date: 2004-8-24" & vbCrLf
s += "*/" & vbCrLf
s += "function " & MsgID & "()" & vbCrLf
s += "{" & vbCrLf
s += "var b;" & vbCrLf
s += "b=false;" & vbCrLf
s += "b=confirm(""" & msg & """);" & vbCrLf
s += "if (b==false)" & vbCrLf
s += "{" & vbCrLf
s += " return false;" & vbCrLf
s += "}" & vbCrLf
s += "else" & vbCrLf
s += "{" & vbCrLf
s += " __doPostBack('" & PostButton.UniqueID & "','') ;" & vbCrLf
s += "}" & vbCrLf
If Not AddScript Is Nothing Then
s += AddScript & vbCrLf
End If
s += "}" & vbCrLf
s += "//-->" & vbCrLf
s += "window.setTimeout(" & MsgID & ",10);" & vbCrLf
s += "</script>" & vbCrLf
'Me.Page.RegisterClientScriptBlock(MsgID, s)
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), MsgID, s)
Return True
End Function
相关代码:
Protected Sub alert()Sub alert(ByVal message As String, ByVal FocusControl As Control, Optional ByVal delay As Integer = 10, Optional ByVal AddScript As String = Nothing, Optional ByVal IsUrl As Boolean = False)
alert_client(message, delay, FocusControl, AddScript, IsUrl)
End Sub
Protected Sub alert()Sub alert(ByVal message As String, Optional ByVal delay As Integer = 10, Optional ByVal AddScript As String = Nothing, Optional ByVal IsUrl As Boolean = False)
alert_client(message, delay, , AddScript, IsUrl)
End Sub
Protected Function UniqueMessageID()Function UniqueMessageID(Optional ByVal id As Integer = 1) As String
Const MessageName As String = "__MessageBox"
If Not Me.Page.ClientScript.IsClientScriptBlockRegistered(MessageName & id.ToString) Then
Return MessageName & id.ToString
Else
Return UniqueMessageID(id + 1)
End If
End Function
alert_client(message, delay, FocusControl, AddScript, IsUrl)
End Sub
Protected Sub alert()Sub alert(ByVal message As String, Optional ByVal delay As Integer = 10, Optional ByVal AddScript As String = Nothing, Optional ByVal IsUrl As Boolean = False)
alert_client(message, delay, , AddScript, IsUrl)
End Sub
Protected Function UniqueMessageID()Function UniqueMessageID(Optional ByVal id As Integer = 1) As String
Const MessageName As String = "__MessageBox"
If Not Me.Page.ClientScript.IsClientScriptBlockRegistered(MessageName & id.ToString) Then
Return MessageName & id.ToString
Else
Return UniqueMessageID(id + 1)
End If
End Function
- .net 服务器端生成alert/confim 消息
- window.confim
- ASP.net从服务器端向客户端弹出alert对话框,但不使页面变成白板
- ASP.net从服务器端向客户端弹出alert对话框,但不使页面变成白板
- linux--------net- tcp----------客户端和服务器端 同步互相收发消息
- AJAX消息提示-Alert
- 6alert消息对话框
- ASP.NET服务器端用C#生成验证码图片
- Flex消息提示框Alert
- 警告(alert 消息对话框)
- AngularJS ui.bootstrap.alert 消息
- AngularJS ui.bootstrap.alert 消息
- 消息对话框:alert、confirm、prompt
- cxf生成服务器端
- wsdl文件生成服务器端
- 服务器端生成JSON数据
- ASP.NET后台alert 提示
- C# asp.net实现Alert
- .NET 泛型的特殊使用
- nullable generic structure
- CAPXOUS AutoComplete 1.2.5 自动完成 AJAX 破解版 注册版
- 关于参加考试的一点想法以及我的系分经历
- 婚礼上,新郎的一段精彩表白
- .net 服务器端生成alert/confim 消息
- gc的用法
- 从javascript语言本身谈项目实战
- 最后的祈祷
- atof ( )【C语言库函数源代码】
- strtod ( ) 和 atof ( )【C语言库函数源代码】
- 工作流参考模型(编号TC00 - 1003)第一章
- is VS. as , ref VS. out
- 《点石成金》译者蒋芳——第四界中国软件技术大会用户交互设计专题演讲现场报导