Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Visual Studio 2012的Asp.Net站点中未显示背景图像_C#_Asp.net_Visual Studio 2010_Visual Studio 2012 - Fatal编程技术网

C# 使用Visual Studio 2012的Asp.Net站点中未显示背景图像

C# 使用Visual Studio 2012的Asp.Net站点中未显示背景图像,c#,asp.net,visual-studio-2010,visual-studio-2012,C#,Asp.net,Visual Studio 2010,Visual Studio 2012,我有两个Visual Studio安装,一个是2010 Ultimate,另一个是2012 Ultimate。“我的网站”中有两个页面显示与PageLoad上的页面相关联的背景图像。这是从目录中提取图像并将其显示为背景图像的代码: public partial class TechCall : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { StringBuilder script =

我有两个Visual Studio安装,一个是2010 Ultimate,另一个是2012 Ultimate。“我的网站”中有两个页面显示与
PageLoad
上的页面相关联的背景图像。这是从目录中提取图像并将其显示为背景图像的代码:

public partial class TechCall : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    StringBuilder script = new StringBuilder();
    script.Append("<script type=\"text/javascript\">");
    script.Append("document.body.style.background = \"url('/Cyber7th/Images/CPUBack2nd.jpg')\";");
    script.Append("document.body.style.backgroundRepeat = 'no-repeat';");
    script.Append("</script>");

    this.ClientScript.RegisterClientScriptBlock(this.GetType(), "changeBackground", script.ToString());
}    
}
编辑:以下是页面的外观:

现在在VisualStudio2010中,这一切都很好。。。在浏览器(这里是Firefox)中查看时,背景图像显示没有问题,所有功能都在那里

但是,对于Visual Studio 2012中的项目,使用相同的代码在相同的浏览器中查看页面进行测试,我得到以下结果:

在浏览器中查看VS 2012中的页面不会显示背景图像-存在一个空白,而不是背景图像。同样,Firefox也在使用,但不管我在2012年使用哪一款(即Chrome和内部浏览器),这种情况都会发生。VS2010显示所有浏览器中的背景图像。这就是我应该看到的输出,就是背景图像


同样,这必须与VS 2012有关,因为我在2010年没有这个问题。也许,如果我在VS 2012中从头开始构建,而不是尝试移植解决方案,也许我就不会有这个问题了?希望这有助于更清楚地解释我的问题

尝试在
页面上使用此按钮来动态更改图像:

Image1.ImageUrl = "~/Images/SampleBackground.png";
在服务器中创建文件夹
Images
,并将背景图像添加到其中。然后您可以使用上面的代码来引用它。这不是使用javascript,而是使用纯c


希望这能有所帮助。

另外,如果有助于了解的话,这两个页面碰巧都在页面中包含.ascx控件。所有其他页面都是通常的.aspx页面。您能给我们提供更多关于实际输出内容的信息吗。您的脚本是否在页面上创建,是否正在运行,迁移时是否遇到您的图像?我的图像目录已经有了这种类型的结构,我使用它来填充我的
RadioButtonList
控件旁边的图像;因此,我的问题不在代码的这一领域。
Image1.ImageUrl = "~/Images/SampleBackground.png";