Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:45:59+00:00 2026-05-30T23:45:59+00:00

I have an asp.net web page. The code: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Login.aspx.cs Inherits=Works.Login

  • 0

I have an asp.net web page. The code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Works.Login" %>
<!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>
      <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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:46:00+00:00Added an answer on May 30, 2026 at 11:46 pm

    Do in the PageLoad, It works.

       protected void Page_Load(object sender, EventArgs e)
        {
            if (PageBody != null)
            {
                 PageBody.Attributes.Add("class", "myClass");
            }
        }
    

    EDIT : Full code to show this is working (since the op is doubtfull abt it)

    My ASPX page

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="SO.WebForm4" %>
    <!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>
        <style>
        body
        {
            background-color:Olive;
        }    
        .myClass
        {
            background-color:Orange;
    
        }
        </style>
    
    </head>
    <body id="PageBody" runat="server">
        <form id="form1" runat="server">
        <div>
          <h2>Testing styles</h2>
           <p>If the bg color is Orange, code is working</p>
        </div>
        </form>
    </body>
    </html>
    

    Codebehind

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace SO
    {
        public partial class WebForm4 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (PageBody != null)
                {
                    PageBody.Attributes.Add("class", "myClass");
                }
            }
        }
    }
    

    and here is the output

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple asp.net user control: <%@ Control Language=C# AutoEventWireup=true CodeBehind=QueryDefinitionItem.ascx.cs Inherits=xxx.UserControls.QueryDefinitionItem %>
I have a simple page per below: Default.aspx <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default
I have an asp.net web page with a ton of code that is handled
I'm writing a web page in ASP.NET. I have some JavaScript code, and I
I have an ASP.NET web page with a Login control on it. When I
I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have
I have an ASP.NET web page that displays a variety of fields that need
I have an asp.net web page written in C#. Using some javascript I popup
I have a asp.net web page with place holder control and Menu control when
I have an ASP.Net web page, which uses a Master Page template. The page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.