JavaScript messes up aspx page (2.0) CSS formatting

Discussion in 'ASP .Net' started by sck10, Jun 9, 2006.

  1. sck10

    sck10 Guest

    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="JavaScript" type="text/JavaScript">
    window.open("srcfinance.aspx?qv01=14&print=printme", "_blank")
    </script>


    Sub Print_Click(ByVal Src As Object, ByVal Args As CommandEventArgs)

    Dim strTarget As String = _
    "<script language=" & strQuote & "javascript" & strQuote & _
    " type=" & strQuote & "text/JavaScript" & strQuote & ">" & _
    "window.open(" & strQuote & "srcfinance.aspx?qv01=" & _
    Me.hdnQV01.Value & "&print=printme" & strQuote & ", " & _
    strQuote & "_blank" & strQuote & ")</script>"

    Response.Write(strTarget)

    End Sub
     
    sck10, Jun 9, 2006
    #1
    1. Advertising

  2. 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 "ClientScriptManager"
    class provided in asp.net 2.0, you can get it through the Page class's
    "ClientScript" property:

    #Page.ClientScript Property
    http://msdn2.microsoft.com/en-us/library/system.web.ui.page.clientscript.asp
    x

    e.g.
    ===========================
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    Dim str As String

    str = "<script language=""javascript""
    >window.open(""PrintPage.aspx?qv01=14&print=printme"",

    ""_blank"");</script>"

    Page.ClientScript.RegisterStartupScript(Me.GetType(),
    "print_script", str)

    End Sub

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

    the clientscriptmanager.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 ClientScriptManager( 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.)
     
    Steven Cheng[MSFT], Jun 12, 2006
    #2
    1. Advertising

  3. 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.)
     
    Steven Cheng[MSFT], Jun 14, 2006
    #3
  4. sck10

    sck10 Guest

    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]" <> wrote in message
    news:G$...
    > 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.)
    >
     
    sck10, Jun 15, 2006
    #4
  5. sck10 wrote:
    > 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...


    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 "ClientScriptManager"
    class provided in asp.net 2.0, you can get it through the Page class's
    "ClientScript" property:

    #Page.ClientScript Property
    http://msdn2.microsoft.com/en-us/library/system.web.ui.page.clientscript.asp
    x

    e.g.
    ===========================
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    Dim str As String

    str = "<script language=""javascript""
    > >window.open(""PrintPage.aspx?qv01=14&print=printme"",

    ""_blank"");</script>"

    Page.ClientScript.RegisterStartupScript(Me.GetType(),
    "print_script", str)

    End Sub

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

    the clientscriptmanager.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 ClientScriptManager( 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.)
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jun 15, 2006
    #5
  6. 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.)
     
    Steven Cheng[MSFT], Jun 16, 2006
    #6
  7. sck10

    sck10 Guest

    Thanks Göran. Worked great...


    "Göran Andersson" <> wrote in message
    news:...
    > sck10 wrote:
    >> 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...

    >
    > 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 "ClientScriptManager"
    > class provided in asp.net 2.0, you can get it through the Page class's
    > "ClientScript" property:
    >
    > #Page.ClientScript Property
    > http://msdn2.microsoft.com/en-us/library/system.web.ui.page.clientscript.asp
    > x
    >
    > e.g.
    > ===========================
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >
    > Dim str As String
    >
    > str = "<script language=""javascript""
    > > >window.open(""PrintPage.aspx?qv01=14&print=printme"",

    > ""_blank"");</script>"
    >
    > Page.ClientScript.RegisterStartupScript(Me.GetType(),
    > "print_script", str)
    >
    > End Sub
    >
    > =======================
    >
    > the clientscriptmanager.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 ClientScriptManager( 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.)
    >
    >
    >
    >
     
    sck10, Jun 16, 2006
    #7
  8. sck10

    sck10 Guest

    Thanks Steve, appreciate the help...


    "Steven Cheng[MSFT]" <> wrote in message
    news:$IL8$...
    > 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.)
    >
     
    sck10, Jun 16, 2006
    #8
  9. 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.)
     
    Steven Cheng[MSFT], Jun 17, 2006
    #9
  10. Any thanks goes to Steven. I just realyed his post. :)

    sck10 wrote:
    > Thanks Göran. Worked great...
    >
    >
    > "Göran Andersson" <> wrote in message
    > news:...
    >> sck10 wrote:
    >>> 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...

    >> 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 "ClientScriptManager"
    >> class provided in asp.net 2.0, you can get it through the Page class's
    >> "ClientScript" property:
    >>
    >> #Page.ClientScript Property
    >> http://msdn2.microsoft.com/en-us/library/system.web.ui.page.clientscript.asp
    >> x
    >>
    >> e.g.
    >> ===========================
    >> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Button1.Click
    >>
    >> Dim str As String
    >>
    >> str = "<script language=""javascript""
    >>>> window.open(""PrintPage.aspx?qv01=14&print=printme"",

    >> ""_blank"");</script>"
    >>
    >> Page.ClientScript.RegisterStartupScript(Me.GetType(),
    >> "print_script", str)
    >>
    >> End Sub
    >>
    >> =======================
    >>
    >> the clientscriptmanager.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 ClientScriptManager( 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.)
    >>
    >>
    >>
    >>

    >
    >
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jun 17, 2006
    #10
  11. sck10

    demmith

    Joined:
    Mar 31, 2008
    Messages:
    1
    demmith, Mar 31, 2008
    #11
    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. Guest
    Replies:
    2
    Views:
    558
    Guest
    Feb 2, 2004
  2. Guest
    Replies:
    0
    Views:
    511
    Guest
    Feb 9, 2004
  3. =?Utf-8?B?TWFydGlu?=

    ASP.Net messes with my form's action attributes!

    =?Utf-8?B?TWFydGlu?=, Apr 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,709
    =?Utf-8?B?TWFydGlu?=
    Apr 6, 2004
  4. Replies:
    11
    Views:
    1,426
  5. Binba
    Replies:
    1
    Views:
    419
Loading...

Share This Page