Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > JavaScript messes up aspx page (2.0) CSS formatting

Reply
Thread Tools

JavaScript messes up aspx page (2.0) CSS formatting

 
 
sck10
Guest
Posts: n/a
 
      06-09-2006
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


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-12-2006
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.)




 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-14-2006
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.)

 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      06-15-2006
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]" <(E-Mail Removed)> wrote in message
news:G$(E-Mail Removed)...
> 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.)
>



 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      06-15-2006
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.)




 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-16-2006
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.)

 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      06-16-2006
Thanks Göran. Worked great...


"Göran Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.)
>
>
>
>



 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      06-16-2006
Thanks Steve, appreciate the help...


"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:$IL8$(E-Mail Removed)...
> 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.)
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-17-2006
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.)

 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      06-17-2006
Any thanks goes to Steven. I just realyed his post.

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

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
filter:chroma messes up the whole page? Binba HTML 1 07-05-2007 10:03 AM
Setting Doctype Messes Up Page?? IWP506@gmail.com HTML 11 09-02-2005 07:16 AM
adding main.aspx.vb & main.aspx.resx under aspx John M ASP .Net 1 05-29-2005 09:27 PM
How to Pass values between from a popup page aspx & a normal page aspx Marco Antonio Montalvo Durán ASP .Net 2 01-23-2004 09:35 PM
How do I post data from aspx page to another aspx page. Sriram Mallajyosula ASP .Net 1 11-05-2003 04:48 PM



Advertisments