Link to home
Start Free TrialLog in
Avatar of kateL
kateL

asked on

Style sheet not being applied?

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?
ASKER CERTIFIED SOLUTION
Avatar of zeroxp
zeroxp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kateL
kateL

ASKER

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?


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).
Avatar of kateL

ASKER

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
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?
Avatar of kateL

ASKER

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
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.
Avatar of kateL

ASKER

hmmm so i guess we'll never know ... strange ...

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