代码改变世界

.net中js脚本封装函数

2004-05-19 17:43  灵感之源  阅读(...)  评论(... 编辑 收藏
我在工作中封装了几个.net中js脚本封装函数:
 

    Public Shared Sub RunScript(ByRef pgeParenet As System.Web.UI.Page, _
                                ByVal strScript As String)
        '名称:RunScript
        '功能:封装执行脚本
        '作者:unruledboy
        '创建:2003/8/20
        '修改:2004/2/5
        '参数::
        '      :
        '返回:成功,True,反之,False
        '说明:
        Dim o_strScript As String = "<script language=javascript>"

        o_strScript = o_strScript & strScript & " </script>"
        pgeParenet.RegisterStartupScript("Script", o_strScript)

    End Sub

    Public Shared Sub ShowMessage(ByRef pgeParenet As System.Web.UI.Page, _
                                  ByVal strMessage As String, _
                                  Optional ByVal scrScript As String = "")
        '名称:ShowMessage
        '功能:封装显示提示
        '作者:unruledboy
        '创建:2003/8/20
        '修改:2004/2/5
        '参数::
        '      :
        '返回:成功,True,反之,False
        '说明:
        Dim o_strErrMessage As String = "<script language=javascript>alert(' "

        o_strErrMessage &= strMessage & "');"

        If scrScript <> "" Then
            o_strErrMessage &= scrScript
        End If
        o_strErrMessage &= " </script>"

        pgeParenet.RegisterStartupScript("Message", o_strErrMessage)

    End Sub

    Public Shared Sub ShowMessageAndRedirect(ByRef pgeParenet As System.Web.UI.Page, _
                                             ByVal strMessage As String, _
                                             ByVal strScript As String)
        '名称:ShowMessageAndRedirect
        '功能:封装显示提示
        '作者:unruledboy
        '创建:2003/8/20
        '修改:2004/2/5
        '参数::
        '      :
        '返回:成功,True,反之,False
        '说明:
        Dim o_strErrMessage As String = "<script language=javascript>alert(' "

        o_strErrMessage &= strMessage & "');this.location.replace('"

        o_strErrMessage &= strScript

        o_strErrMessage &= "'); </script>"

        pgeParenet.RegisterStartupScript("Message", o_strErrMessage)

    End Sub