IsStartupScriptregistered has become obsolete and use clientscript.

Last post 09-11-2009 3:00 PM by anas. 1 replies.

Sort Posts:

  • IsStartupScriptregistered has become obsolete and use clientscript.

    09-11-2009, 1:40 PM
    • Member
      23 point Member
    • cplusplus1
    • Member since 01-27-2007, 2:28 PM
    • Posts 190

          I am switching from 1.1 to 2.0 and facing some problems with code, Getting a message on senderpage.Is startupScriptregisted has become obsolete instead use clientscript.

     

    But when i replaced this:senderpage.RegisterStartupScript(alertKey, strScript)

    to Clientscript.RegisterStartupScript(alertKey, strScript) getting another error message saying overloaded.

     

    Public Function CreateMessageAlert(ByVal senderpage As System.Web.UI.Page, ByVal alertMsg As String, ByVal alertKey As String)
                Dim strScript As String

                strScript = " <script language=JavaScript>"
                strScript += "alert ('" + alertMsg + "');</script>"
                If (Not senderpage.IsStartupScriptRegistered(alertKey)) Then
                    senderpage.RegisterStartupScript(alertKey, strScript)
                End If

            End Function

     

    Also does'nt know what to put as return line at the end of function.

     

    thankyou very much for the helpful info.

  • Re: IsStartupScriptregistered has become obsolete and use clientscript.

    09-11-2009, 3:00 PM
    Answer
    • All-Star
      60,921 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,865
    • Moderator

    cplusplus1:
    Also does'nt know what to put as return line at the end of function.

    Since it will not return a value, change the function  to Sub instead.

    Also, you don't need to take care of adding <script> tag , just pass true for the 4'th parameter of the RegisterStartupScript method.

    This is the modified version of that method:

        Public Sub CreateMessageAlert(ByVal senderpage As System.Web.UI.Page, ByVal alertMsg As String, ByVal alertKey As String)
            Dim strScript As String = "alert ('" + alertMsg + "');</script>"
            If (Not senderpage.ClientScript.IsStartupScriptRegistered(alertKey)) Then
                senderpage.ClientScript.RegisterStartupScript(senderpage.GetType(), alertKey, strScript, True)
            End If
        End Sub


    Regards,

    Anas Ghanem | Blog

Page 1 of 1 (2 items)