473,624 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting DIV content programmaticall y, how??

Hey

ASP.NET 2.0

In my webpage (.aspx) I have this tag:
<div id="test" class="pageTitl e">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.H tmlControls tttt = (System.Web.UI. HtmlControls)
System.Web.UI.H tmlControls.Htm lGenericControl .cell.FindContr ol("test");

Any suggestions?

Jeff
Mar 28 '07 #1
3 31638
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.NO SPAMwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hey

ASP.NET 2.0

In my webpage (.aspx) I have this tag:
<div id="test" class="pageTitl e">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.H tmlControls tttt = (System.Web.UI. HtmlControls)
System.Web.UI.H tmlControls.Htm lGenericControl .cell.FindContr ol("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.Inn erHtml = "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.NO SPAMwrote:
Hey

ASP.NET 2.0

In my webpage (.aspx) I have this tag:
<div id="test" class="pageTitl e">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.H tmlControls tttt = (System.Web.UI. HtmlControls)
System.Web.UI.H tmlControls.Htm lGenericControl .cell.FindContr ol("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
2027
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 change the Page Orientation to Landscape: mso-page-orientation:landscape;. I tried to produce the Excel Page, save it as HTML, open in text editor and then copy and paste Excel generated settings. But it did not help. If anybody resolved this...
11
10255
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 don't understand what will happen when I distribute my front-end to some other PC. How will Access know where is File DSN ? Is there any way that I set the connection programmatically. For example, some login form with neccessary informations ?...
2
1444
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 store localized values in resource files without assigning them programmatically? Which means: I can't just set a labels text as usual and change this value in a localized resource file which is being assigned dynamically regarding the regional...
5
6797
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 way is using javascript - does anybody have a sample for this ? Thanks
4
2493
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 event does not trig at all!
1
1418
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, IMHO.
3
1855
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 "fix" the content-type to one type? thanks...
7
2746
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 have <SCRIPT language=JavaScript> <!-- Begin function filterNum(obj) { re = /^$|!|$|<|>|"|'|%|,|&|%|;/g; // remove spcial charcters obj.value = obj.value.replace(re, ""); }
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.