473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

setting DIV content programmatically, how??

Hey

ASP.NET 2.0

In my webpage (.aspx) I have this tag:
<div id="test" class="pageTitle">Hello World</div>

I'm wondering how I in Page_Load event can change the "Hello World" text to
something else...?
First I need to get a reference to this div tag, so I'm trying this code,
I'm NOT sure it works:
System.Web.UI.HtmlControls tttt = (System.Web.UI.HtmlControls)
System.Web.UI.HtmlControls.HtmlGenericControl.cell .FindControl("test");

Any suggestions?

Jeff
Mar 28 '07 #1
3 31623
To use a control on server side you need to set runat=server. Then you can
refer to it just by id, no need to call FindControl.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hey

ASP.NET 2.0

In my webpage (.aspx) I have this tag:
<div id="test" class="pageTitle">Hello World</div>

I'm wondering how I in Page_Load event can change the "Hello World" text
to
something else...?
First I need to get a reference to this div tag, so I'm trying this code,
I'm NOT sure it works:
System.Web.UI.HtmlControls tttt = (System.Web.UI.HtmlControls)
System.Web.UI.HtmlControls.HtmlGenericControl.cell .FindControl("test");

Any suggestions?

Jeff


Mar 28 '07 #2
Hi Jeff,

You need a runat="server" attribute to be able to access it
programatically from the Page_Load method.

For example:

ASPX
<div id="divChangeMe" runat="server">Hello World</div>

CODE BEHIND (In Page_Load)
divChangeMe.InnerHtml = "Goodby World!";

N.B. you may have to go from Source to Designer to get access to the
div tag in the code beind... At least i have to sometimes.

Hope this helps...

Justin

Mar 28 '07 #3
On Mar 28, 9:00 am, "Jeff" <it_consulta...@hotmail.com.NOSPAMwrote:
Hey

ASP.NET 2.0

In my webpage (.aspx) I have this tag:
<div id="test" class="pageTitle">Hello World</div>

I'm wondering how I in Page_Load event can change the "Hello World" text to
something else...?
First I need to get a reference to this div tag, so I'm trying this code,
I'm NOT sure it works:
System.Web.UI.HtmlControls tttt = (System.Web.UI.HtmlControls)
System.Web.UI.HtmlControls.HtmlGenericControl.cell .FindControl("test");

Any suggestions?
Since everybody else has given you perfect answers here I'll just fill
in the fact that you can get ANY controls (inclusive the body tag,
title tag etc) to become a "runat='server'" tag...
This also gives you nice capabilities to use the ~ operator like for
instance:
<a href="~/MyPage.aspx" runat="server">xxx</a>
This will map to e.g. localhost/MyApp/MyPage.aspx when run in the
debugger...

Nifty little trick :)

Thomas

--
http://ajaxwidgets.com
ASP.NET 2.0 Ajax Widgets

Mar 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Yelena Kaplun | last post by:
Hi, I'm trying to customize print settings while streaming HTML content into Excel. I'm using ASP.NET 1.1 and Excel 2003. While some printer settings like Margins are working correctly, I cannot...
11
by: Zlatko Matić | last post by:
Hello. I have a MS Access front-end working with PostgreSQL database. I have successfully created saved File DSN. My paa-through queries are referring to that file as well as linked tables. But I...
2
by: Philipp Sumi | last post by:
Hello I have to start an Asp.net project that involves i18n, so I was doing some reading on the subject. I'm not sure (and I *really* hope I'm wrong) but is it true, that there is no way to...
5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
4
by: Paul | last post by:
Hi! When I add a bound column programatically, like: BoundColumn bc = new BoundColumn(); bc.DataField = "myField"; bc.SortExpression = "myField"; myGrid.Columns.Add(bc); the SortCommand...
1
by: Max Paulousky | last post by:
Why I can set MasterPage file programmatically, but cannot set property ContentPlaceHolderId for Content control programmatically? There are no limitation in documentation. It is not logically,...
3
by: skyy | last post by:
Hi.. i am doing a uploading CGI perl script... I notice that when i send data using form submission with POST method, the Content-type changes with different type of file used. Is it possible to...
7
by: ThePope78705 | last post by:
Hi all, I have a web form that is generated on the fly. I need to insert some javascript into the form to do validation on the contents of each text box when the text box loses focus. here is what I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.