[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Style sheet not being applied?

Posted on 2007-07-30
8
Medium Priority
?
492 Views
Last Modified: 2008-02-01
Hi Expert,

When I have the following code::
Response.Write("<Script language=javascript>alert('Please select an invoice ')</Script>");
my style sheet disappears/is not applied.

Even when I have Response.Write("anything") on my page it's the same.

Why is this and how can I stop it from happening?
0
Comment
Question by:kateL
  • 4
  • 4
8 Comments
 
LVL 5

Accepted Solution

by:
zeroxp earned 200 total points
ID: 19597682
first check the syntax of where you include your stylesheet. to use <style/> or <link/> you have to put that in the <head/> element.
and please note the response.write will write information right on top of the page, that is outside all element(if you have a look of the html source, you will find that is before your DOCTYPE and <html/> element).  this will make your markup no longer well formed. so if you need to add some client side script to the page you should use Page.ClientScript.RegisterClientScriptBlock()

but when i tested it even i did Response.Write("some thing") the browser still pick up the style i set in a stylesheet, so maybe check for the stylesheet first.
0
 

Author Comment

by:kateL
ID: 19598010
Thanks zeroxp,
My css is in the Head of my page

What would RegisterClientScriptBlock do?
MSDN says:
The RegisterClientScriptBlock method adds a script block to the top of the rendered page.

Is that not just the same as adding the <script> block to the head of the page, what the difference?


0
 
LVL 5

Expert Comment

by:zeroxp
ID: 19598146
the RegisterClientScriptBlock just give you the ability to add some client side script when you have to do that from server code (eg. when you want display a message dialog to display some server error message).
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:kateL
ID: 19598379
thanks zeroxp,

it happens everywhere is my code.

When i do:
Page.ClientScript.RegisterStartupScript(this.GetType(), this.UniqueID, "parent.window.frames[\'LeftFrame\'].location.href = '../../LeftMenu.aspx?selectedCustomerID=" + _customerID + "';", true);

the style sheet on LeftFrame is scraped

when i do:
Response.Write("<Script language=javascript>alert('Please select an invoice ')</Script>");

on a completely different page the style sheet of that page is scraped.

I apply the css like this:
<head runat="server">
    <title>Untitled Page</title>
    <link rel="stylesheet" href="../../styles/main.css" type="text/css" />
 </head>

can you see anything wrong with it.

Thanks a million for the help
0
 
LVL 5

Expert Comment

by:zeroxp
ID: 19606132
i tried to write some thing to the page and the stylesheet still worked. here is my files:
///////.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test01._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Email Test Page</title>
    <link rel="stylesheet" type="text/css" href="test.css" />
</head>
<body>
    <form id="form1" runat="server">
    <div class="textSpecial">
       Some Text: ABC DEF GHI JKL
       <div id="Test">Other Text</div>
    </div>
    </form>
</body>
</html>


////////.cs
      protected void Page_Load(object sender, EventArgs e)
      {
         if (!IsPostBack)
         {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "Key01", "<script type=\"text/javascript\">alert('gogoog');</script>", false);
            Response.Write("<script type=\"text/javascript\">alert('blah');</script>");
            ClientScript.RegisterStartupScript(this.GetType(), "Key02", "<script>alert(1);</script>");
            Response.Write("<Script language=javascript>alert('Please select an invoice ')</Script>");
         }
      }

////////.css
.textSpecial {font-size:larger; color:#ff0000;}
#Test {font-size:100px; background-color:#f00; color:#fff; position:absolute; top:500px; left:500px;}

so is that cause your stylesheet completely not working or only some attributes not right?
0
 

Author Comment

by:kateL
ID: 19606612
I got it (or you did I should say!)

When I use:
Response.Write("<Script language=javascript>alert('Please select an invoice ')</Script>");

it doesn't work but when I use:
Page.ClientScript.RegisterStartupScript(this.GetType(), this.UniqueID, "alert('Please select an invoice ');", true);

Must be what you said "markup no longer well formed"

But strange that when you use Response.Write your css are applied just fine.

What happens when you do:
Response.Write("<script type=\"text/javascript\">alert('blah');</script>");
in a button click event (not your Page_Load event) because that's what I am doing?

I'd be interested to know
0
 
LVL 5

Expert Comment

by:zeroxp
ID: 19613670
i pasted the same code into a Button_Click event handler, it still came up fine with the style.
i tried to change DOCTYPE to XHTML 1.0 strict/Transitional, HTML 4.01, XHTML 1.1 or no DOCTYPE declaration. they all worked fine.
0
 

Author Comment

by:kateL
ID: 19615019
hmmm so i guess we'll never know ... strange ...

Thanks a lot zeroxp, you've been a great help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question