JavaScript messes up aspx page (2.0) CSS formatting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sck10

    JavaScript messes up aspx page (2.0) CSS formatting

    Hello,

    I have a page with an ImageButton that is used to redirect to another page.
    When the page first opens, everything looks as expected. However, when I
    click on the image, the new page opens as expected. However, when I go back
    to the original page, all the font sizes are larger. Its as if by clicking
    on the ImageButton, my CSS formatting was discarded.

    When I look at the source for the following code, this is what I get:

    <script language="JavaS cript" type="text/JavaScript">
    window.open("sr cfinance.aspx?q v01=14&print=pr intme", "_blank")
    </script>


    Sub Print_Click(ByV al Src As Object, ByVal Args As CommandEventArg s)

    Dim strTarget As String = _
    "<script language=" & strQuote & "javascript " & strQuote & _
    " type=" & strQuote & "text/JavaScript" & strQuote & ">" & _
    "window.ope n(" & strQuote & "srcfinance.asp x?qv01=" & _
    Me.hdnQV01.Valu e & "&print=printme " & strQuote & ", " & _
    strQuote & "_blank" & strQuote & ")</script>"

    Response.Write( strTarget)

    End Sub


  • Steven Cheng[MSFT]

    #2
    RE: JavaScript messes up aspx page (2.0) CSS formatting

    Hello Sck10,

    Thank you for posting in ASPNET newsgroup.

    As for the ASP.NET page css formatting issue, I've performed some local
    test according to your description and I did manage to reproduce the same
    behavior(when the new page opened, original page's css formatting get
    lost...).

    And based on my further test, I think the problem is caused by the approach
    you used to register the client-script. In your page, you use
    "Response.Write " to output client-script, this is doable, however, not
    recommended because "Response.Write " will always output the string/text
    before the page's html content, this will make the page output not a valid
    html/xhtml document(I think you found the output script block at the top of
    the page source when viewing the source in client browser, correct?).
    Though IE or other popular browser can correct parse this, this is not
    always guaranteed to work. And in this case, the cause the css format not
    correctly get resolved.

    In stead of using "Response.Write ", you can use the "ClientScriptMa nager"
    class provided in asp.net 2.0, you can get it through the Page class's
    "ClientScri pt" property:

    #Page.ClientScr ipt Property
    Gets a ClientScriptManager object used to manage, register, and add script to the page.

    x

    e.g.
    =============== ============
    Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
    System.EventArg s) Handles Button1.Click

    Dim str As String

    str = "<script language=""java script""[color=blue]
    >window.open("" PrintPage.aspx? qv01=14&print=p rintme"",[/color]
    ""_blank"") ;</script>"

    Page.ClientScri pt.RegisterStar tupScript(Me.Ge tType(),
    "print_scri pt", str)

    End Sub

    =============== ========

    the clientscriptman ager.xxxx method can ensure those script blocks to be
    registered in the proper location in the page body. Also, I've performed
    local test and after changed to use the ClientScriptMan ager( to register
    script), the css formatting issue went away.

    Hope this helps.

    Regards,

    Steven Cheng
    Microsoft Online Community Support


    =============== =============== =============== =====

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    =============== =============== =============== =====


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)




    Comment

    • Steven Cheng[MSFT]

      #3
      RE: JavaScript messes up aspx page (2.0) CSS formatting

      Hi Steven,

      Have you got any any progress on this issue or does my last reply help you
      a little? If there is still anything we can help, please feel free to post
      here.

      Regards,

      Steven Cheng
      Microsoft MSDN Online Support Lead


      =============== =============== =============== =====

      When responding to posts, please "Reply to Group" via your newsreader so
      that others may learn and benefit from your issue.

      =============== =============== =============== =====


      This posting is provided "AS IS" with no warranties, and confers no rights.



      Get Secure! www.microsoft.com/security
      (This posting is provided "AS IS", with no warranties, and confers no
      rights.)

      Comment

      • sck10

        #4
        Re: JavaScript messes up aspx page (2.0) CSS formatting

        Hi Steve,

        I'm sorry, but you are referring to your last reply, which my reader is not
        showing. Actually, its showing your reply below as the only reply. To
        answer your question, no, I haven't made any progress on this issue...
        --
        Thanks,

        sck10



        "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
        news:G$QvpK8jGH A.4948@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
        > Hi Steven,
        >
        > Have you got any any progress on this issue or does my last reply help you
        > a little? If there is still anything we can help, please feel free to post
        > here.
        >
        > Regards,
        >
        > Steven Cheng
        > Microsoft MSDN Online Support Lead
        >
        >
        > =============== =============== =============== =====
        >
        > When responding to posts, please "Reply to Group" via your newsreader so
        > that others may learn and benefit from your issue.
        >
        > =============== =============== =============== =====
        >
        >
        > This posting is provided "AS IS" with no warranties, and confers no
        > rights.
        >
        >
        >
        > Get Secure! www.microsoft.com/security
        > (This posting is provided "AS IS", with no warranties, and confers no
        > rights.)
        >[/color]


        Comment

        • Göran Andersson

          #5
          Re: JavaScript messes up aspx page (2.0) CSS formatting

          sck10 wrote:[color=blue]
          > Hi Steve,
          >
          > I'm sorry, but you are referring to your last reply, which my reader is not
          > showing. Actually, its showing your reply below as the only reply. To
          > answer your question, no, I haven't made any progress on this issue...[/color]

          Here is a re-post of Stevens first reply:



          Hello Sck10,

          Thank you for posting in ASPNET newsgroup.

          As for the ASP.NET page css formatting issue, I've performed some local
          test according to your description and I did manage to reproduce the same
          behavior(when the new page opened, original page's css formatting get
          lost...).

          And based on my further test, I think the problem is caused by the approach
          you used to register the client-script. In your page, you use
          "Response.Write " to output client-script, this is doable, however, not
          recommended because "Response.Write " will always output the string/text
          before the page's html content, this will make the page output not a valid
          html/xhtml document(I think you found the output script block at the top of
          the page source when viewing the source in client browser, correct?).
          Though IE or other popular browser can correct parse this, this is not
          always guaranteed to work. And in this case, the cause the css format not
          correctly get resolved.

          In stead of using "Response.Write ", you can use the "ClientScriptMa nager"
          class provided in asp.net 2.0, you can get it through the Page class's
          "ClientScri pt" property:

          #Page.ClientScr ipt Property
          Gets a ClientScriptManager object used to manage, register, and add script to the page.

          x

          e.g.
          =============== ============
          Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
          System.EventArg s) Handles Button1.Click

          Dim str As String

          str = "<script language=""java script""[color=blue][color=green]
          > >window.open("" PrintPage.aspx? qv01=14&print=p rintme"",[/color][/color]
          ""_blank"") ;</script>"

          Page.ClientScri pt.RegisterStar tupScript(Me.Ge tType(),
          "print_scri pt", str)

          End Sub

          =============== ========

          the clientscriptman ager.xxxx method can ensure those script blocks to be
          registered in the proper location in the page body. Also, I've performed
          local test and after changed to use the ClientScriptMan ager( to register
          script), the css formatting issue went away.

          Hope this helps.

          Regards,

          Steven Cheng
          Microsoft Online Community Support


          =============== =============== =============== =====

          When responding to posts, please "Reply to Group" via your newsreader so
          that others may learn and benefit from your issue.

          =============== =============== =============== =====


          This posting is provided "AS IS" with no warranties, and confers no rights.



          Get Secure! www.microsoft.com/security
          (This posting is provided "AS IS", with no warranties, and confers no
          rights.)




          Comment

          • Steven Cheng[MSFT]

            #6
            Re: JavaScript messes up aspx page (2.0) CSS formatting

            Thank you for your help Guffa,

            Hi Sck10,

            Guffa has helped repost my first response. Please feel free to let me know
            if you still have any problem on accessing it.

            Regards,

            Steven Cheng
            Microsoft MSDN Online Support Lead


            =============== =============== =============== =====

            When responding to posts, please "Reply to Group" via your newsreader so
            that others may learn and benefit from your issue.

            =============== =============== =============== =====


            This posting is provided "AS IS" with no warranties, and confers no rights.



            Get Secure! www.microsoft.com/security
            (This posting is provided "AS IS", with no warranties, and confers no
            rights.)

            Comment

            • sck10

              #7
              Re: JavaScript messes up aspx page (2.0) CSS formatting

              Thanks Göran. Worked great...


              "Göran Andersson" <guffa@guffa.co m> wrote in message
              news:O3Mz4dJkGH A.4828@TK2MSFTN GP04.phx.gbl...[color=blue]
              > sck10 wrote:[color=green]
              >> Hi Steve,
              >>
              >> I'm sorry, but you are referring to your last reply, which my reader is
              >> not showing. Actually, its showing your reply below as the only reply.
              >> To answer your question, no, I haven't made any progress on this issue...[/color]
              >
              > Here is a re-post of Stevens first reply:
              >
              >
              >
              > Hello Sck10,
              >
              > Thank you for posting in ASPNET newsgroup.
              >
              > As for the ASP.NET page css formatting issue, I've performed some local
              > test according to your description and I did manage to reproduce the same
              > behavior(when the new page opened, original page's css formatting get
              > lost...).
              >
              > And based on my further test, I think the problem is caused by the
              > approach
              > you used to register the client-script. In your page, you use
              > "Response.Write " to output client-script, this is doable, however, not
              > recommended because "Response.Write " will always output the string/text
              > before the page's html content, this will make the page output not a valid
              > html/xhtml document(I think you found the output script block at the top
              > of
              > the page source when viewing the source in client browser, correct?).
              > Though IE or other popular browser can correct parse this, this is not
              > always guaranteed to work. And in this case, the cause the css format not
              > correctly get resolved.
              >
              > In stead of using "Response.Write ", you can use the "ClientScriptMa nager"
              > class provided in asp.net 2.0, you can get it through the Page class's
              > "ClientScri pt" property:
              >
              > #Page.ClientScr ipt Property
              > http://msdn2.microsoft.com/en-us/lib...ientscript.asp
              > x
              >
              > e.g.
              > =============== ============
              > Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
              > System.EventArg s) Handles Button1.Click
              >
              > Dim str As String
              >
              > str = "<script language=""java script""[color=green][color=darkred]
              > > >window.open("" PrintPage.aspx? qv01=14&print=p rintme"",[/color][/color]
              > ""_blank"") ;</script>"
              >
              > Page.ClientScri pt.RegisterStar tupScript(Me.Ge tType(),
              > "print_scri pt", str)
              >
              > End Sub
              >
              > =============== ========
              >
              > the clientscriptman ager.xxxx method can ensure those script blocks to be
              > registered in the proper location in the page body. Also, I've performed
              > local test and after changed to use the ClientScriptMan ager( to register
              > script), the css formatting issue went away.
              >
              > Hope this helps.
              >
              > Regards,
              >
              > Steven Cheng
              > Microsoft Online Community Support
              >
              >
              > =============== =============== =============== =====
              >
              > When responding to posts, please "Reply to Group" via your newsreader so
              > that others may learn and benefit from your issue.
              >
              > =============== =============== =============== =====
              >
              >
              > This posting is provided "AS IS" with no warranties, and confers no
              > rights.
              >
              >
              >
              > Get Secure! www.microsoft.com/security
              > (This posting is provided "AS IS", with no warranties, and confers no
              > rights.)
              >
              >
              >
              >[/color]


              Comment

              • sck10

                #8
                Re: JavaScript messes up aspx page (2.0) CSS formatting

                Thanks Steve, appreciate the help...


                "Steven Cheng[MSFT]" <stcheng@online .microsoft.com> wrote in message
                news:$IL8$TOkGH A.4828@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
                > Thank you for your help Guffa,
                >
                > Hi Sck10,
                >
                > Guffa has helped repost my first response. Please feel free to let me know
                > if you still have any problem on accessing it.
                >
                > Regards,
                >
                > Steven Cheng
                > Microsoft MSDN Online Support Lead
                >
                >
                > =============== =============== =============== =====
                >
                > When responding to posts, please "Reply to Group" via your newsreader so
                > that others may learn and benefit from your issue.
                >
                > =============== =============== =============== =====
                >
                >
                > This posting is provided "AS IS" with no warranties, and confers no
                > rights.
                >
                >
                >
                > Get Secure! www.microsoft.com/security
                > (This posting is provided "AS IS", with no warranties, and confers no
                > rights.)
                >[/color]


                Comment

                • Steven Cheng[MSFT]

                  #9
                  Re: JavaScript messes up aspx page (2.0) CSS formatting

                  You're welcome :-)

                  Regards,

                  Steven Cheng
                  Microsoft MSDN Online Support Lead


                  =============== =============== =============== =====

                  When responding to posts, please "Reply to Group" via your newsreader so
                  that others may learn and benefit from your issue.

                  =============== =============== =============== =====


                  This posting is provided "AS IS" with no warranties, and confers no rights.



                  Get Secure! www.microsoft.com/security
                  (This posting is provided "AS IS", with no warranties, and confers no
                  rights.)

                  Comment

                  • Göran Andersson

                    #10
                    Re: JavaScript messes up aspx page (2.0) CSS formatting

                    Any thanks goes to Steven. I just realyed his post. :)

                    sck10 wrote:[color=blue]
                    > Thanks Göran. Worked great...
                    >
                    >
                    > "Göran Andersson" <guffa@guffa.co m> wrote in message
                    > news:O3Mz4dJkGH A.4828@TK2MSFTN GP04.phx.gbl...[color=green]
                    >> sck10 wrote:[color=darkred]
                    >>> Hi Steve,
                    >>>
                    >>> I'm sorry, but you are referring to your last reply, which my reader is
                    >>> not showing. Actually, its showing your reply below as the only reply.
                    >>> To answer your question, no, I haven't made any progress on this issue...[/color]
                    >> Here is a re-post of Stevens first reply:
                    >>
                    >>
                    >>
                    >> Hello Sck10,
                    >>
                    >> Thank you for posting in ASPNET newsgroup.
                    >>
                    >> As for the ASP.NET page css formatting issue, I've performed some local
                    >> test according to your description and I did manage to reproduce the same
                    >> behavior(when the new page opened, original page's css formatting get
                    >> lost...).
                    >>
                    >> And based on my further test, I think the problem is caused by the
                    >> approach
                    >> you used to register the client-script. In your page, you use
                    >> "Response.Write " to output client-script, this is doable, however, not
                    >> recommended because "Response.Write " will always output the string/text
                    >> before the page's html content, this will make the page output not a valid
                    >> html/xhtml document(I think you found the output script block at the top
                    >> of
                    >> the page source when viewing the source in client browser, correct?).
                    >> Though IE or other popular browser can correct parse this, this is not
                    >> always guaranteed to work. And in this case, the cause the css format not
                    >> correctly get resolved.
                    >>
                    >> In stead of using "Response.Write ", you can use the "ClientScriptMa nager"
                    >> class provided in asp.net 2.0, you can get it through the Page class's
                    >> "ClientScri pt" property:
                    >>
                    >> #Page.ClientScr ipt Property
                    >> http://msdn2.microsoft.com/en-us/lib...ientscript.asp
                    >> x
                    >>
                    >> e.g.
                    >> =============== ============
                    >> Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
                    >> System.EventArg s) Handles Button1.Click
                    >>
                    >> Dim str As String
                    >>
                    >> str = "<script language=""java script""[color=darkred]
                    >>>> window.open(""P rintPage.aspx?q v01=14&print=pr intme"",[/color]
                    >> ""_blank"") ;</script>"
                    >>
                    >> Page.ClientScri pt.RegisterStar tupScript(Me.Ge tType(),
                    >> "print_scri pt", str)
                    >>
                    >> End Sub
                    >>
                    >> =============== ========
                    >>
                    >> the clientscriptman ager.xxxx method can ensure those script blocks to be
                    >> registered in the proper location in the page body. Also, I've performed
                    >> local test and after changed to use the ClientScriptMan ager( to register
                    >> script), the css formatting issue went away.
                    >>
                    >> Hope this helps.
                    >>
                    >> Regards,
                    >>
                    >> Steven Cheng
                    >> Microsoft Online Community Support
                    >>
                    >>
                    >> =============== =============== =============== =====
                    >>
                    >> When responding to posts, please "Reply to Group" via your newsreader so
                    >> that others may learn and benefit from your issue.
                    >>
                    >> =============== =============== =============== =====
                    >>
                    >>
                    >> This posting is provided "AS IS" with no warranties, and confers no
                    >> rights.
                    >>
                    >>
                    >>
                    >> Get Secure! www.microsoft.com/security
                    >> (This posting is provided "AS IS", with no warranties, and confers no
                    >> rights.)
                    >>
                    >>
                    >>
                    >>[/color]
                    >
                    >[/color]

                    Comment

                    Working...