Accessing an HTML element from a child control

D

darrel

I have a page structured as such:

page.aspx
<title>
control1.ascx
control2.ascx

The page, may or may not have a title tag. If it doesn't, control1 writes it
out.

I'd like to be able to manipulate the text in the TITLE tag from control2.
Is that possible? If so, what would be the logic behind it? I asked a
similiar question before, and it was suggested that I set the TITLE tag to
"runat=server" and then declare it in my codebehind. The catch is that
control2 won't know if the title is in the parent page or control1, so I'm
not sure how to address it.

-Darrel
 
M

Martin Dechev

Hi,

A very dirty solution:

Add a literal in the page (<asp:literal id="literalSetTitle"
runat="server"/>). Then in the controls:

[C#]
Literal literalSetTitle = Page.FindControl("literalSetTitle") as Literal;
if(literalSetTitle != null)
literalSetTitle.Text = string.Format(
@"<script>document.title='{0}';</script>",
"New Title")

And replace "New Title" with the one you need. Note that the last control to
execute this code will set the title.

Hope this helps
Martin
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top