如何使.net服务器端生成alert/confim消息?
如何使.net服务器端生成alert/confim消息?
一、服务器端生成alert代码
message :消息内容
delay :延迟多长时间之后弹出消息框
FocusControl :关闭对话框之后焦点所在
AddScript:关闭对话框之后页面处罚的事件
IsUrl:关闭对话框之后转向的页面
PrivateSubalert_client(ByValmessageAsString,ByValdelayAsInteger,OptionalByValFocusControlAsControl=Nothing,OptionalByValAddScriptAsString=Nothing,OptionalByValIsUrlAsBoolean=False)
DimsAsString,msgAsString,MsgIDAsString
DimsbAsNewSystem.Text.StringBuilder(message)
sb.Replace(vbCrLf," ")
sb.Replace("'","'")
sb.Replace("""","""")
msg=sb.ToString()
MsgID=UniqueMessageID()
s="<scriptlanguage='javascript'>"&vbCrLf
s+="function"&MsgID&"()"&vbCrLf
s+="{"&vbCrLf
s+="alert("""&msg&""");"&vbCrLf
IfNotFocusControlIsNothingThen
s+="window.document.all['"&FocusControl.ClientID.ToString()&"'].focus();"&vbCrLf
IfString.Compare(FocusControl.GetType.ToString,"System.Web.UI.WebControls.LinkButton")<>0Then
s+="window.document.all['"&FocusControl.ClientID.ToString()&"'].select();"&vbCrLf
EndIf
EndIf
IfNotAddScriptIsNothingThen
IfIsUrlThen
s+="window.location='"&AddScript&"';"&vbCrLf
Else
s+=AddScript&vbCrLf
EndIf
EndIf
s+="}"&vbCrLf
s+="//-->"&vbCrLf
Ifdelay=0Then
s+=(MsgID&"();")
Else
s+="window.setTimeout("&MsgID&","&delay&");"&vbCrLf
EndIf
s+="</script>"&vbCrLf
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),MsgID,s)
EndSub
DimsAsString,msgAsString,MsgIDAsString
DimsbAsNewSystem.Text.StringBuilder(message)
sb.Replace(vbCrLf," ")
sb.Replace("'","'")
sb.Replace("""","""")
msg=sb.ToString()
MsgID=UniqueMessageID()
s="<scriptlanguage='javascript'>"&vbCrLf
s+="function"&MsgID&"()"&vbCrLf
s+="{"&vbCrLf
s+="alert("""&msg&""");"&vbCrLf
IfNotFocusControlIsNothingThen
s+="window.document.all['"&FocusControl.ClientID.ToString()&"'].focus();"&vbCrLf
IfString.Compare(FocusControl.GetType.ToString,"System.Web.UI.WebControls.LinkButton")<>0Then
s+="window.document.all['"&FocusControl.ClientID.ToString()&"'].select();"&vbCrLf
EndIf
EndIf
IfNotAddScriptIsNothingThen
IfIsUrlThen
s+="window.location='"&AddScript&"';"&vbCrLf
Else
s+=AddScript&vbCrLf
EndIf
EndIf
s+="}"&vbCrLf
s+="//-->"&vbCrLf
Ifdelay=0Then
s+=(MsgID&"();")
Else
s+="window.setTimeout("&MsgID&","&delay&");"&vbCrLf
EndIf
s+="</script>"&vbCrLf
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),MsgID,s)
EndSub
二、服务器生成confim
message :消息内容
PostButton :关闭对话框之后触发的页面postback事件
AddScript:关闭对话框之后页面处罚的事件
ProtectedFunctionconfirm(ByValmessageAsString,ByValPostButtonAsButton,OptionalByValAddScriptAsString=Nothing)AsBoolean
DimsAsString,msgAsString,MsgIDAsString
DimsbAsNewSystem.Text.StringBuilder(message)
sb.Replace(vbCrLf," ")
sb.Replace("'","'")
sb.Replace("""","""")
msg=sb.ToString()
MsgID=UniqueMessageID()
s="<scriptlanguage='javascript'>"&vbCrLf
s+="<!--"&vbCrLf
s+="/*ClientAlertFunction"&vbCrLf
s+="CopyRightAPJCorp.com"&vbCrLf
s+="Author:bss(Bianshusen@apjcorp.com)"&vbCrLf
s+="Date:2004-8-24"&vbCrLf
s+="*/"&vbCrLf
s+="function"&MsgID&"()"&vbCrLf
s+="{"&vbCrLf
s+="varb;"&vbCrLf
s+="b=false;"&vbCrLf
s+="b=confirm("""&msg&""");"&vbCrLf
s+="if(b==false)"&vbCrLf
s+="{"&vbCrLf
s+="returnfalse;"&vbCrLf
s+="}"&vbCrLf
s+="else"&vbCrLf
s+="{"&vbCrLf
s+="__doPostBack('"&PostButton.UniqueID&"','');"&vbCrLf
s+="}"&vbCrLf
IfNotAddScriptIsNothingThen
s+=AddScript&vbCrLf
EndIf
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)
ReturnTrue
EndFunction
DimsAsString,msgAsString,MsgIDAsString
DimsbAsNewSystem.Text.StringBuilder(message)
sb.Replace(vbCrLf," ")
sb.Replace("'","'")
sb.Replace("""","""")
msg=sb.ToString()
MsgID=UniqueMessageID()
s="<scriptlanguage='javascript'>"&vbCrLf
s+="<!--"&vbCrLf
s+="/*ClientAlertFunction"&vbCrLf
s+="CopyRightAPJCorp.com"&vbCrLf
s+="Author:bss(Bianshusen@apjcorp.com)"&vbCrLf
s+="Date:2004-8-24"&vbCrLf
s+="*/"&vbCrLf
s+="function"&MsgID&"()"&vbCrLf
s+="{"&vbCrLf
s+="varb;"&vbCrLf
s+="b=false;"&vbCrLf
s+="b=confirm("""&msg&""");"&vbCrLf
s+="if(b==false)"&vbCrLf
s+="{"&vbCrLf
s+="returnfalse;"&vbCrLf
s+="}"&vbCrLf
s+="else"&vbCrLf
s+="{"&vbCrLf
s+="__doPostBack('"&PostButton.UniqueID&"','');"&vbCrLf
s+="}"&vbCrLf
IfNotAddScriptIsNothingThen
s+=AddScript&vbCrLf
EndIf
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)
ReturnTrue
EndFunction
相关代码:
ProtectedSubalert(ByValmessageAsString,ByValFocusControlAsControl,OptionalByValdelayAsInteger=10,OptionalByValAddScriptAsString=Nothing,OptionalByValIsUrlAsBoolean=False)
alert_client(message,delay,FocusControl,AddScript,IsUrl)
EndSub
ProtectedSubalert(ByValmessageAsString,OptionalByValdelayAsInteger=10,OptionalByValAddScriptAsString=Nothing,OptionalByValIsUrlAsBoolean=False)
alert_client(message,delay,,AddScript,IsUrl)
EndSub
ProtectedFunctionUniqueMessageID(OptionalByValidAsInteger=1)AsString
ConstMessageNameAsString="__MessageBox"
IfNotMe.Page.ClientScript.IsClientScriptBlockRegistered(MessageName&id.ToString)Then
ReturnMessageName&id.ToString
Else
ReturnUniqueMessageID(id+1)
EndIf
EndFunction
alert_client(message,delay,FocusControl,AddScript,IsUrl)
EndSub
ProtectedSubalert(ByValmessageAsString,OptionalByValdelayAsInteger=10,OptionalByValAddScriptAsString=Nothing,OptionalByValIsUrlAsBoolean=False)
alert_client(message,delay,,AddScript,IsUrl)
EndSub
ProtectedFunctionUniqueMessageID(OptionalByValidAsInteger=1)AsString
ConstMessageNameAsString="__MessageBox"
IfNotMe.Page.ClientScript.IsClientScriptBlockRegistered(MessageName&id.ToString)Then
ReturnMessageName&id.ToString
Else
ReturnUniqueMessageID(id+1)
EndIf
EndFunction