2012-10-19 38 views
0

我可以使用VS設計器打開文檔屬性並更改背景屬性。但我似乎無法找到一種方法來加載頁面時動態更改它。這可以在代碼隱藏中完成,還是隻能在JavaScript中完成?在代碼中設置文檔背景圖像

+2

簡單的舊CSS有什麼問題? –

回答

-2

你可以試試這個上標記:

<head runat="server"> 
    <title></title> 
    <asp:Literal ID="Literal1" runat="server"></asp:Literal> 
</head> 

<body class="bodyStyle"> 

這在代碼隱藏:

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      String ImgUrl = "/Images/image.png"; 
      Literal1.Text = "<style>.bodyStyle {background-image: url('" + ImgUrl + "');}</style>"; 
     } 
    } 

您可以以編程方式更改圖像鏈接根據需要

+0

-1:'