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?
When I have the following code::
Response.Write("<Script language=javascript>alert(
my style sheet disappears/is not applied.
Even when I have Response.Write("anything")
Why is this and how can I stop it from happening?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
ASKER
thanks zeroxp,
it happens everywhere is my code.
When i do:
Page.ClientScript.Register StartupScr ipt(this.G etType(), this.UniqueID, "parent.window.frames[\'Le ftFrame\'] .location. href = '../../LeftMenu.aspx?selec tedCustome rID=" + _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.cs s" type="text/css" />
</head>
can you see anything wrong with it.
Thanks a million for the help
it happens everywhere is my code.
When i do:
Page.ClientScript.Register
the style sheet on LeftFrame is scraped
when i do:
Response.Write("<Script language=javascript>alert(
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.cs
</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.c s" 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.RegisterClien tScriptBlo ck(this.Ge tType(), "Key01", "<script type=\"text/javascript\">a lert('gogo og');</scr ipt>", false);
Response.Write("<script type=\"text/javascript\">a lert('blah ');</scrip t>");
ClientScript.RegisterStart upScript(t his.GetTyp e(), "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?
///////.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.c
<!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.RegisterClien
Response.Write("<script type=\"text/javascript\">a
ClientScript.RegisterStart
Response.Write("<Script language=javascript>alert(
}
}
////////.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?
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.Register StartupScr ipt(this.G etType(), 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\">a lert('blah ');</scrip t>");
in a button click event (not your Page_Load event) because that's what I am doing?
I'd be interested to know
When I use:
Response.Write("<Script language=javascript>alert(
it doesn't work but when I use:
Page.ClientScript.Register
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\">a
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.
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.
ASKER
hmmm so i guess we'll never know ... strange ...
Thanks a lot zeroxp, you've been a great help
Thanks a lot zeroxp, you've been a great help
ASKER
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?