Ctrl+F5能成功应用CSS(居中,红色字体),但是点击Button1_Click()后CSS样式失效,但客户端test()正常.请问是怎么回事,如何解决.要能在服务端解决,而不是像本例中用javascript在客户端解决.谢谢!CSS: ~/App_Themes/myskin/StyleSheet.css
#master_main{margin:0px auto; width:800px; color:Red; }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" Theme="myskin" %><!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>无标题页</title>
<script type="text/javascript">
function test()
{
alert('客户端点击没问题~');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="master_main">
<table style="border-right: #000099 1px solid; border-top: #000099 1px solid; border-left: #000099 1px solid; border-bottom: #000099 1px solid">
<tr>
<td style="width: 100px">
1</td>
<td style="width: 100px">
2</td>
<td style="width: 100px">
3</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="test()"/>
</div>
</form>
</body>
</html>[code=C#]using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('为何点击后CSS无效了?')</script>");
}
}
[/code]
#master_main{margin:0px auto; width:800px; color:Red; }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" Theme="myskin" %><!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>无标题页</title>
<script type="text/javascript">
function test()
{
alert('客户端点击没问题~');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="master_main">
<table style="border-right: #000099 1px solid; border-top: #000099 1px solid; border-left: #000099 1px solid; border-bottom: #000099 1px solid">
<tr>
<td style="width: 100px">
1</td>
<td style="width: 100px">
2</td>
<td style="width: 100px">
3</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="test()"/>
</div>
</form>
</body>
</html>[code=C#]using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('为何点击后CSS无效了?')</script>");
}
}
[/code]
解决方案 »
- 关于MVC2缓存
- 。net 程序里 怎么样把 doc 文件 转换成 swf
- 页面变量???????????????
- Repeater 嵌套问题!急!在线等!
- 简单问题~~!
- 求在线统计的做法及代码
- ASP.NET C# 怎样在网页上自动打开EXCEL文件,不要有打开的提示???谢谢帮忙!!!!
- 请问HTML5中Video播放MP4时执行JS脚本的问题。
- DataGrid动态绑定DataTable的问题!!急,在线等!
- asp.net突然不能用了!现实链接localhost------
- 请问SOAOffice NTKO、iWebOffice三种有什么不同?
- Ajax control toolkit安装后,有些控件不能拖放到页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
试试
去掉后CSS就直接无效了~~~
1.Literal,在页面中添加一个Literal控件,然后Literal1.Text="<script>alert('为何点击后CSS无效了?') </script>");
2. Page.RegisterClientScriptBlock(""," <script>alert('为何点击后CSS无效了?') </script>");
强烈建议使用第一种
输出在页面代码最顶端了. 破坏了布局的CSS .
Response.Write("<script>alert('为何点击后CSS无效了?');window.location.href='aa.aspx'</script>");//假设你的当前页面为aa.aspx
{
ClientScript.RegisterStartupScript(typeof(string),"js","alert('这样就不会无效了');",true);
}
用这个
ClientScript.RegisterStartupScript()