---
title: "Add attribute to the body failed"  
description: "Add attribute to the body failed"  
author: "Anonymous User"  
published: 2014-08-22  
updated: 2014-08-22  
canonical: https://www.mindstick.com/forum/2075/add-attribute-to-the-body-failed  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Add attribute to the body failed

I have an [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [web page](https://www.mindstick.com/forum/718/sql-server-report-alignment-to-center-of-web-page).

**The [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Works.Login" %><html xmlns="http://www.w3.org/1999/xhtml" >   <head runat="server">      <title></title>      <link rel="stylesheet" type="text/css" href="/styles/source/style.css" />   </head>   <body id="PageBody" runat="server">      <form id="form1" runat="server">         <div style="text-align: center" >And in code behind I want to add something to the body attribute.protected void Page_PreRender(object sender, EventArgs e){        if (PageBody != null)        {            PageBody.Attributes.Add("class", "some_image");
```

However I found it doesn't work at all. I stepped through into the code and found there is an [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling).

InnerText = '((System.Web.UI.HtmlControls.HtmlContainerControl)(((System.Web.UI.HtmlControls.HtmlGenericControl)(PageBody)))).InnerText' threw an exception of type 'System.Web.HttpException'}

Thanks for your help.

## Replies

### Reply by Sumit Kesarwani

Hi Chintoo, \

This works for me:

PageBody.Attributes["class"] = "some_image";


---

Original Source: https://www.mindstick.com/forum/2075/add-attribute-to-the-body-failed

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
