By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,491 Members | 3,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,491 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Hi Paul,

Here's a way to set the title using codebehind.

http://authors.aspalliance.com/kenc/faq5.aspx

Ken

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
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

"Paul" wrote:
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

Nov 19 '05 #3

P: n/a
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 ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:83**********************************@microsof t.com...
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

"Paul" wrote:
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

Nov 19 '05 #4

P: n/a
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

"Juan T. Llibre" wrote:
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 ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:83**********************************@microsof t.com...
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

"Paul" wrote:
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


Nov 19 '05 #5

P: n/a

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 19 '05 #6

P: n/a
Thanks, this worked Ken.

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

- Paul
"Ken Cox [Microsoft MVP]" wrote:
Hi Paul,

Here's a way to set the title using codebehind.

http://authors.aspalliance.com/kenc/faq5.aspx

Ken

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
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


Nov 19 '05 #7

P: n/a
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.

"Juan T. Llibre" wrote:
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 ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:83**********************************@microsof t.com...
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

"Paul" wrote:
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


Nov 19 '05 #8

P: n/a
re:
It can be changed dynamically.
Would you explain how ?


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"vMike" <Mi************@spamnotgewarren.com.delete> wrote in message
news:DS*************@newsread1.news.atl.earthlink. net...
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 19 '05 #9

P: n/a
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.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com... 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.

"Juan T. Llibre" wrote:
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 ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:83**********************************@microsof t.com...
> 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
>
> "Paul" wrote:
>
>> 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


Nov 19 '05 #10

P: n/a

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
re:
It can be changed dynamically.


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
Nov 19 '05 #11

P: n/a
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.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"vMike" <Mi************@spamnotgewarren.com.delete> wrote in message
news:st*************@newsread1.news.atl.earthlink. net...

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
re:
> It can be changed dynamically.


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

Nov 19 '05 #12

P: n/a

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:#Y**************@TK2MSFTNGP10.phx.gbl...
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.
Nov 19 '05 #13

P: n/a

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:#Y**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #14

P: n/a
Thanks.
The added explanation fills in what was missing before.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"vMike" <Mi************@spamnotgewarren.com.delete> wrote in message
news:M3*************@newsread1.news.atl.earthlink. net...

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:#Y**************@TK2MSFTNGP10.phx.gbl...
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


Nov 19 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.