473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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
14 3454
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
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
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
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

"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
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
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
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
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

"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
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

"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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Don | last post by:
I want the server-side php script to return a browser page that is essentially a copy of the original client page that contained the <form> which referenced the php script in the first place....
2
by: Kingdom | last post by:
I have a SelectBoxes.asp page that is working with multiple selection dropdown boxes to extract data and total the selection prices. Tom & Bob were kind enough to give me a big help getting this...
4
by: dmiller23462 | last post by:
I'm trying to create a submission page for users to request PC/LAN Access....If they select "Yes" in the field asking about if they need Non Standard Software, I want several other HTML fields to...
4
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would...
4
by: Kevin Vogler | last post by:
I need to read the value of a hidden field on a remote HTML page and then use that value in a form submit on my local page. How can I read the hidden field programatically? Thanks in advance....
4
by: Magnus Blomberg | last post by:
Hello! I have a problem when using a hidden field to send a value to the server. Below you can see my code in simplyfied versions. What I'm trying to do is: 1. The user browses for a picture...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
1
by: fugaki | last post by:
Hi everyone I'm learning asp, and i downloaded this script to teach me how to post form data from a webpage to an access database. I put it on the server so i could make sure that it worked, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.