Setting attributes of webform from source code

N

Newton

Hi,

I am working with ASP.NET using C#. I put some labels,
buttons and editboxes on a webform. But i need how to
change a background color of the webform from the source
code. In windows application it is easy, because I can
call name of that form. But how is it in web
application ?

Somebody help me please,

thank you

Peter
 
C

Chris Jackson

OK, so it's slightly more complicated with WebForms to do this dynamically,
but anything that can be done in HTML can be done with ASP.NET, so let's get
to work.

First, set up your body tag to run in the server:

<body runat="server" id="myBody">
....
</body>

Now, you can set up a declaration of that in your codebehind:

protected HtmlGenericControl myBody;

Because you are using the generic control, you don't get direct access to
the bgcolor attribute, so you have to use the generic implementation in your
Page_Load event:

myBody.Attributes.Add("bgcolor", "#ffffcc");

There may be an easier way, perhaps, but this will get the job done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top