By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

JavaScript messes up aspx page (2.0) CSS formatting

P: n/a
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
Jun 9 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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/lib...ientscript.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=printm e"",

""_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.)


Jun 12 '06 #2

P: n/a
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.)

Jun 14 '06 #3

P: n/a
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]" <st*****@online.microsoft.com> wrote in message
news:G$**************@TK2MSFTNGXA01.phx.gbl...
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.)

Jun 15 '06 #4

P: n/a
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/lib...ientscript.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=printm e"",

""_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.)


Jun 15 '06 #5

P: n/a
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.)

Jun 16 '06 #6

P: n/a
Thanks Göran. Worked great...
"Göran Andersson" <gu***@guffa.com> wrote in message
news:O3**************@TK2MSFTNGP04.phx.gbl...
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/lib...ientscript.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=printm e"",

""_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.)

Jun 16 '06 #7

P: n/a
Thanks Steve, appreciate the help...
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:$I**************@TK2MSFTNGXA01.phx.gbl...
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.)

Jun 16 '06 #8

P: n/a
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.)

Jun 17 '06 #9

P: n/a
Any thanks goes to Steven. I just realyed his post. :)

sck10 wrote:
Thanks Göran. Worked great...
"Göran Andersson" <gu***@guffa.com> wrote in message
news:O3**************@TK2MSFTNGP04.phx.gbl...
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/lib...ientscript.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.)


Jun 17 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.