ASP.NET Message Box causing problems with SmartNavigation property

Discussion in 'ASP .Net' started by =?Utf-8?B?TWFydHo=?=, Jul 28, 2005.

  1. 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????
    --
    Regards,
    Martz
    =?Utf-8?B?TWFydHo=?=, Jul 28, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?TWFydHo=?=

    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
    http://www.OdeToCode.com/blogs/scott/

    On Thu, 28 Jul 2005 07:58:04 -0700, "Martz"
    <> wrote:

    >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????
    Scott Allen, Jul 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Ruegsegger

    SmartNavigation and Panels causing debug error

    Chris Ruegsegger, Aug 6, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    449
    Yan-Hong Huang[MSFT]
    Aug 8, 2003
  2. Inigo Jimenez
    Replies:
    0
    Views:
    386
    Inigo Jimenez
    Nov 28, 2003
  3. Dagong Wang

    SmartNavigation and Redirect Problems

    Dagong Wang, Apr 20, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    469
    Peter Rilling
    Apr 21, 2004
  4. Nestus
    Replies:
    3
    Views:
    1,096
    Nestus
    Aug 20, 2004
  5. Gnarlodious
    Replies:
    4
    Views:
    17,553
    elizas
    May 5, 2010
Loading...

Share This Page