ASP.NET Message Box causing problems with SmartNavigation property

Discussion in 'ASP .Net' started by Guest, Jul 28, 2005.

  1. Guest

    Guest Guest

    Hello everyone

    I just use a MsgBox component for ASP.NET using Methods such as Render and
    OnPreRender and JavaScript involved to get a simple Confirmation Box in
    client side, but the funny thing is when I go SmartNavigation property equal
    True the MessageBox does not come up!

    But if you open another window and return to the browser you can see the
    pop-up window !!!

    Any Suggestions?

    This is the complete code to Confirmation Pop-up:

    Imports System.ComponentModel
    Imports System.Web.UI
    Imports System.Web.UI.WebControls

    Public Class MsgBox
    Inherits System.Web.UI.WebControls.WebControl
    Implements IPostBackEventHandler

    Private _Message As String
    Private _Key As String
    Private _PostBackOnYes As Boolean
    Private _PostBackOnNo As Boolean

    Public Event YesChoosed(ByVal sender As Object, ByVal Key As String)
    Public Event NoChoosed(ByVal sender As Object, ByVal Key As String)

    Public Sub ShowConfirmation(ByVal Message As String, ByVal Key As
    String, ByVal PostBackOnYes As Boolean, ByVal PostBackOnNo As Boolean)
    _Message = "ÑaÑa" & Message
    _Key = Key
    _PostBackOnYes = PostBackOnYes
    _PostBackOnNo = PostBackOnNo
    End Sub

    Public Sub ShowMessage(ByVal Message As String)
    _Message = Message
    End Sub

    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
    If Not MyBase.Page.IsClientScriptBlockRegistered("MsgBox") Then
    Page.RegisterClientScriptBlock("MsgBox", FuncionJava1())
    End Sub

    Private Function FuncionJava1() As String
    Dim miPostBackOnYes As String = "MsgBoxTextoMensaje="""";"
    Dim miPostBackOnNo As String = "MsgBoxTextoMensaje="""";"

    If _PostBackOnYes Then
    miPostBackOnYes = Page.GetPostBackEventReference(Me, "Yes" & _Key)
    End If
    If _PostBackOnNo Then
    miPostBackOnNo = Page.GetPostBackEventReference(Me, "No_" & _Key)
    End If

    Return "<script language=""javascript""> " & _
    "var MsgBoxTipoMensaje; " & _
    "var MsgBoxTextoMensaje; " & _
    "window.attachEvent(""onfocus"", MsgBoxMostrarMensaje); " & _
    "function MsgBoxMostrarMensaje() { " & _
    "if (MsgBoxTextoMensaje) { " & _
    "if (MsgBoxTextoMensaje != """") { " & _
    "if (MsgBoxTipoMensaje==2) {" & _
    " alert(MsgBoxTextoMensaje); " & _
    "} else {" & _
    "if (confirm(MsgBoxTextoMensaje)) { " & _
    miPostBackOnYes & _
    "} else { " & _
    miPostBackOnNo & _
    "}} MsgBoxTextoMensaje=""""; " & _
    " }}} </script>"
    End Function


    <Security.Permissions.PermissionSetAttribute(Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    Protected Overrides Sub Render(ByVal writer As
    System.Web.UI.HtmlTextWriter)
    If ModoDisenio(Me) Then
    writer.Write(Me.ID)
    Else
    If _Message <> String.Empty Then
    Dim miSB As System.Text.StringBuilder = New
    System.Text.StringBuilder(_Message)
    miSB.Replace(Microsoft.VisualBasic.vbCr, " "c)
    miSB.Replace(Microsoft.VisualBasic.vbLf, " "c)
    miSB.Replace("""", "'"c)

    If miSB.ToString.StartsWith("ÑaÑa") Then
    Me.Page.Response.Write("<script>MsgBoxTipoMensaje=1;
    MsgBoxTextoMensaje=""" + _
    miSB.ToString.Substring(4) + """;</script>")
    Else
    Me.Page.Response.Write("<script>MsgBoxTipoMensaje=2;
    MsgBoxTextoMensaje=""" + _
    miSB.ToString + """;</script>")
    End If
    miSB = Nothing
    End If
    End If
    End Sub

    Private Shared Function ModoDisenio(ByVal QueControl As _
    System.Web.UI.WebControls.WebControl) As Boolean
    Dim DesignMode As Boolean = False
    Try
    DesignMode = QueControl.Site.DesignMode
    Catch : End Try
    Return DesignMode
    End Function

    Public Sub RaisePostBackEvent(ByVal eventArgument As String) _
    Implements IPostBackEventHandler.RaisePostBackEvent
    Select Case eventArgument.Substring(0, 3)
    Case "Yes"
    RaiseEvent YesChoosed(Me, eventArgument.Substring(3))
    Case "No_"
    RaiseEvent NoChoosed(Me, eventArgument.Substring(3))
    End Select
    End Sub

    End Class


    ************************************************

    You can save this code and generate a Component, after that I am using this
    code:

    MsgBox1.ShowConfirmation("Do you want to delete this record?", "BORRAR",
    True, False)

    AND if you click and SmartNavigation equal True the Windows will not comes up!

    I realized that and some computers does not appear the window even if the
    NavigationSmart is False !!!

    Any Suggestions????
     
    Guest, Jul 28, 2005
    #1
    1. Advertisements

  2. Guest

    Scott Allen Guest

    Hi Martz:

    SmartNav causes all sorts of difficulties when JavaScript and DHTML
    are involved on the page. The only good workaround is to get rid of
    SmartNav.

    If you need to persist scroll position, there are some techniques to
    do that for 1.1 on the web.
     
    Scott Allen, Jul 28, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.