Title Properties

  • Thread starter Thread starter Daniel Groh
  • Start date Start date
D

Daniel Groh

Maybe someone knows how to "fix" this question!
I need to send this to the <title><%=objTitulo.TituloPagina;%></title>
This does not work, How can i send my object.propertie value to the title
tag ? I didn't find any property Title in WebForm1 class!

Thanks in advance!

Daniel
 
Perhaps not the most efficient way, but this should work fine (at least in
IE).
this.RegisterClientScriptBlock("someName","<script>document.title='Hello
World';</script>");

Hope this helps,

Dan Cox
DISCLAIMER: This may not be the best way to handle this, but it should work.
 
thats a C# and not a Jscript u know ?
objTitulo.TituloPagina <- this comes from my ASCX

How do I apply objTitulo.TituloPagina (C#) into a <script></script> ???

Thanks in advance
 
OK, so then there's essentially 2 options that shine out at me in this
little amount of time.
1. In the Page_Load event of the .aspx page holding the .ascx, you run:
this.RegisterClientScriptBlock("someName","<script>document.title='"
+ objTitulo.TituloPagina + "';</script>");

or

2. In the user control (.ascx), you can add an <asp:Literal runat=server
id=myLiteral> and set it's value, like so:
myLiteral.Text = "<script>document.title='" + objTitulo.TituloPagina +
"';</script>";

Hope this helps,
Dan Cox
DISCLAIMER: I haven't tested either approach.
 
I believe that the <%=objTitulo.TituloPagina;%> will still work in ASP.NET.

1. Make sure that the <title></title> tag is not contained by (nested in) any tags with runat="server".
2. Make sure that "objTitulo" is in the scope of the ASPX page. This means that it must be declared in your code-behind with no
less access than "public" or "protected", and must be an instance or static variable on the class-level.
3. Make sure that "objTitulo" is intialized in the contructor of the ASPX page.

That should do it.
 
CSharper said:
OK, so then there's essentially 2 options that shine out at me in this
little amount of time.
1. In the Page_Load event of the .aspx page holding the .ascx, you run:
this.RegisterClientScriptBlock("someName","<script>document.title='"
+ objTitulo.TituloPagina + "';</script>");

or

2. In the user control (.ascx), you can add an <asp:Literal runat=server
id=myLiteral> and set it's value, like so:
myLiteral.Text = "<script>document.title='" + objTitulo.TituloPagina +
"';</script>";

3. Create a custom control which overrides Render to emit the title
html.

I've got something a bit like this for dynamically emitting stylesheet
declarations.
 
You could always do this which should be the asp.net way:

aspx page:

<title id="_title" runat="server">old title</title>

in codebehing/inline code:

HtmlGenericControl _title;
protected void page_load( ... )
{
_title.InnerHtml = "new title";
}

beware:
There is a bug in visual studio (at least in VS.NET 2002) that [id="_title"
runat="server"]
is stripped from the title tag when opening the aspx page in design view

cheers,
mortb
 
I got this

---------------------------
Microsoft Internet Explorer
---------------------------
Unable to find script library
'/aspnet_client/system_web/1_1_4322/WebUIValidation.js'. Try placing this
file manually, or reinstall by running 'aspnet_regiis -c'.
---------------------------
OK
---------------------------

trying to use that:

this.RegisterClientScriptBlock("someName","<script>document.title='"+
objTitulo.TituloPagina + "';</script>");

Something else ? Maybe a customcontrol is the solution, but this really
doesn't make me happy... =/

Thank u all

Daniel
 
Greate Man, solved mortb! =D

But now a curiosity...here at work is running the code this.RegisterClientScriptBlock("Au","<script>document.title='teste';</script>");

at home it does not work, i got a message error:

Unable to find script library
'/aspnet_client/system_web/1_1_4322/WebUIValidation.js'. Try placing this
file manually, or reinstall by running 'aspnet_regiis -c'.

What culd it be ?

--
Daniel Groh
CTF Technologies do Brasil LTDA
Analista Programador
Fone: 11 3837-4203
Email: (e-mail address removed)

mortb said:
You could always do this which should be the asp.net way:

aspx page:

<title id="_title" runat="server">old title</title>

in codebehing/inline code:

HtmlGenericControl _title;
protected void page_load( ... )
{
_title.InnerHtml = "new title";
}

beware:
There is a bug in visual studio (at least in VS.NET 2002) that [id="_title"
runat="server"]
is stripped from the title tag when opening the aspx page in design view

cheers,
mortb

Daniel Groh said:
Maybe someone knows how to "fix" this question!
I need to send this to the <title><%=objTitulo.TituloPagina;%></title>
This does not work, How can i send my object.propertie value to the title
tag ? I didn't find any property Title in WebForm1 class!

Thanks in advance!

Daniel
 
Back
Top