Programatically set the Page Title and/or Hidden Form Field?

G

Guest

I want to set the page title and/or a form hidden field programatically
through ASP.Net.

I do not want to use something like...
<% sTitle ="My Title" %>
<html><title><%=sTitle%></title>.....

I want to completely seperate the code from presentation.

I would like to do the same thing for a value of a hidden form field but
like the title, I do not want to do something like below:
<input type="hidden" id="HiddenField" value="<%=sHiddenFieldValue%>">

Can I set these values programaically or though some Server Controls?

TIA
 
G

Guest

Paul,

I tend to use this mechanism

for Title
<Title id="objTitle" runat="server"></Title>

on code behind page add
HtmlGenericControl objTitle;
to the datamembers list.

now you can access it programmatically in code behind
same goes for hidden field
<input type="hidden" name="objHiddenField" id="name="objHiddenField"
runat="server">

on codebehind this should automatically appear in datamembers list as
HtmlInputHidden objHiddenField;

if you dont see it add it the way you add titleobject shown above. Now you
can access it programmatically as well

HTH

Regards,

Hermit Dave
http://hdave.blogspot.com
 
J

Juan T. Llibre

Dave,

I've often wondered why anybody would go through
the trouble of setting a Page Title programmatically,
if the Page Title can't be changed dynamically.

If all I'm doing is setting a fixed title, why would I want to do that ?
( Except to waste valuable programming and processing time. )

Isn't it simpler to write the title in the aspx page ?

What is gained by setting a Page Title in code-behind ?
 
G

Guest

Juan,

i agree with your comments though i have to admit i have used code to
programmatically write the page title.

The problem i wrote an ecommerce site and i would like to make it
customisable, just so that i could modify the title from config file

The person i wrote it for wanted change some text like she wanted the site
name to preceed etc. too much of a pain to do it page after page. Solution do
it in code behind. Access main part from config and just the page related
data from page itself.
Also helps cause i set whole lot of meta tags. I do that was well
programmatically so that she can modify the keywords etc.

Apart from that, Can't think of a better reason,

Regards,

Hermit Dave
http://hdave.blogspot.com
 
V

vMike

Juan T. Llibre said:
Dave,

I've often wondered why anybody would go through
the trouble of setting a Page Title programmatically,
if the Page Title can't be changed dynamically.

It can be changed dynamically. The reason is because of SEO.
 
G

Guest

Thanks, this worked Ken.

As for the hidden form input, would the .innertext property work as well?

- Paul
 
G

Guest

Here is the reason that I am doing this.

I am writing a restaurant software that is used by multiple restaurants. The
title of the page is created dynamically depending on the restaurant
selected.

Don't know what you mean when you say that the Page title can't be changed
dynamically? I do it all the time.

Thanks for the help. Your suggestion worked for the title.
 
J

Juan T. Llibre

re:
I am writing a restaurant software that is used by multiple restaurants.
The title of the page is created dynamically depending on the restaurant
selected.

That's a good use for that capability.
Is that a "dynamic" feature of your software, though ?

Isn't the *particular* restaurant's name hard-coded somewhere
in the files you deliver to them, thereby allowing the name of
the restaurant to be inserted ?

re:
Don't know what you mean when you say that the
Page title can't be changed dynamically? I do it all the time.

Maybe we understand different things for "dynamically".

Can you change the page title depending on the page's contents ?
( For example... )

Can you change the page's title to anything else than
what you wrote in code ? If so, please post sample code.
 
V

vMike

Juan T. Llibre said:
I put a control in the head tag. The control has a placeholder (others have
used other methods). In code, I have a simple class like this.

Public Class mgTitleControl
Inherits UserControl

Protected plc1 as placeholder

Writeonly Public Property TitleText() as string

Set (ByVal TitleText as string)
dim strText as string
if TitleText = "default" then
plc1.controls.clear
dim ctl as control = loadcontrol("inc/title.ascx")
plc1.controls.add(ctl)
else
strText = TitleText
plc1.controls.clear
plc1.controls.add(New literalcontrol("<title>" & strtext &
"</title>"))
end if
End Set
End Property
End Class
 
J

Juan T. Llibre

I'm not sure if I'd classify that as "dynamically".

Is the content of "inc/title.ascx" set in stone ?
Or can that be modified at runtime ?

Basically, what I'm saying is : can you fill in a Title from, say,
a database column, so that the title fits the other content which
is getting dynamically written to the page ?

*That* would be dynamic.

Reading a page title from somewhere where a title sits static in code,
doesn't classify as "dynamic" in my book.
 
V

vMike

Juan T. Llibre said:
I'm not sure if I'd classify that as "dynamically".

Is the content of "inc/title.ascx" set in stone ?
Or can that be modified at runtime ?

Basically, what I'm saying is : can you fill in a Title from, say,
a database column, so that the title fits the other content which
is getting dynamically written to the page ?

*That* would be dynamic.

Reading a page title from somewhere where a title sits static in code,
doesn't classify as "dynamic" in my book.
I guess you didn't really look at the code. The inc/title.ascx is a default
generic title. You can set the title dynamically by setting it's TitleText
propery to "Anyting you want from you database or from anywhere else.". I
use it all the time.
 
V

vMike

Juan T. Llibre said:
I'm not sure if I'd classify that as "dynamically".

Is the content of "inc/title.ascx" set in stone ?
Or can that be modified at runtime ?

Basically, what I'm saying is : can you fill in a Title from, say,
a database column, so that the title fits the other content which
is getting dynamically written to the page ?

*That* would be dynamic.
Let me explain it better to you. In my code for the page I have a control.
Say I call it DynTitleCtl which is a mgTitleControl class control. Then in
my page code in the Page_Load I have DynTitleCtl.TitleText = "Some text from
a database record." If I have DynTitleCtl.TitleText = "default" it will load
a default fixed title. I probably could have just added a default property
to the title control itself, but the code I posted was just a snip as there
is more process going on then I showed in my post.

Make sense?

Mike


Mike
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top