Showing posts with label master. Show all posts
Showing posts with label master. Show all posts

Thursday, March 22, 2012

Trouble with Javascript when converting 2003 webproject to a 2005 project using Master Pag

Hi All,

We've got an VS.2003 ASPNET (VB) webproject which we would like to convert
to VS.2005 so that we can make use of the Master Page feature. Converting
the initial pages to 2005 is not such a problem (some minor errors) but we
run into trouble when we're trying to insert a converted page into a master
page content-placeholder.

The original page has some Javascript in it which ofcourse references to
controls in a form in the page. The form name is "frmContent", the control
is "txtSubject". In Javascript this is refered to as:
document.frmContent.txtSubject. However when this page is in the content of
a master page the frmContent form had vanished from the rendered page (view
source). Not only that: the txtSubject control is renamed to:
ctl00_phMasterContent_txtSubject. Obviously the existing Javascript will not
function anymore.

Another strange thing: suddenly there's a new <form> in the page which I
haven't created: aspnetForm. I think this is created by the master page but
I'm not sure.

Has anyone encountered the same problems that I'm facing and what's the most
simple solution? Rewriting all Javascript is going to be a lot of work..

TIA
Friso Wiskerke> Another strange thing: suddenly there's a new <form> in the page which I
> haven't created: aspnetForm. I think this is created by the master page but
> I'm not sure.

Yes, this will be the server-side form created by default in the master
page; all the content placeholders should fall within it so you can use
server controls within your Content blocks without putting a <form
runat="server"> on each individual page.

> The original page has some Javascript in it which ofcourse references to
> controls in a form in the page. The form name is "frmContent", the control
> is "txtSubject".

If the form is server-side (runat="server"), then it could create
problems, as you may usually only have one server-side form per page
(which the master has provided for you)...

> However when this page is in the content of
> a master page the frmContent form had vanished from the rendered page (view
> source).

...so, you shouldn't need to have separate <form> elements in the
content-placeholder, and removing those tags may cause the contents to
render properly.

> the txtSubject control is renamed to:
> ctl00_phMasterContent_txtSubject. Obviously the existing Javascript will not
> function anymore.

This "name mangling" is necessary to keep identifiers unique within
different parts of the page. You can work around it by substituting the
result of <% txtSubject.ClientID %> into the Javascript at the relevant
points in place of txtSubject, and the correct form name instead of
frmContent; however, this might be tedious if you have large amounts of
code that needs modifying in this way. You could possibly set up a
Javascript object called frmContent [and call the real form something
different] then add members to it with names corresponding to the
original names, pointing to the actual controls with mangled names
inserted as above.

Trouble with Javascript when converting 2003 webproject to a 2005 project using Maste

Hi All,
We've got an VS.2003 ASPNET (VB) webproject which we would like to convert
to VS.2005 so that we can make use of the Master Page feature. Converting
the initial pages to 2005 is not such a problem (some minor errors) but we
run into trouble when we're trying to insert a converted page into a master
page content-placeholder.
The original page has some Javascript in it which ofcourse references to
controls in a form in the page. The form name is "frmContent", the control
is "txtSubject". In Javascript this is refered to as:
document.frmContent.txtSubject. However when this page is in the content of
a master page the frmContent form had vanished from the rendered page (view
source). Not only that: the txtSubject control is renamed to:
ctl00_phMasterContent_txtSubject. Obviously the existing Javascript will not
function anymore.
Another strange thing: suddenly there's a new <form> in the page which I
haven't created: aspnetForm. I think this is created by the master page but
I'm not sure.
Has anyone encountered the same problems that I'm facing and what's the most
simple solution? Rewriting all Javascript is going to be a lot of work..
TIA
Friso Wiskerke> Another strange thing: suddenly there's a new <form> in the page which I
> haven't created: aspnetForm. I think this is created by the master page bu
t
> I'm not sure.
Yes, this will be the server-side form created by default in the master
page; all the content placeholders should fall within it so you can use
server controls within your Content blocks without putting a <form
runat="server"> on each individual page.

> The original page has some Javascript in it which ofcourse references to
> controls in a form in the page. The form name is "frmContent", the control
> is "txtSubject".
If the form is server-side (runat="server"), then it could create
problems, as you may usually only have one server-side form per page
(which the master has provided for you)...

> However when this page is in the content of
> a master page the frmContent form had vanished from the rendered page (vie
w
> source).
...so, you shouldn't need to have separate <form> elements in the
content-placeholder, and removing those tags may cause the contents to
render properly.

> the txtSubject control is renamed to:
> ctl00_phMasterContent_txtSubject. Obviously the existing Javascript will n
ot
> function anymore.
This "name mangling" is necessary to keep identifiers unique within
different parts of the page. You can work around it by substituting the
result of <% txtSubject.ClientID %> into the Javascript at the relevant
points in place of txtSubject, and the correct form name instead of
frmContent; however, this might be tedious if you have large amounts of
code that needs modifying in this way. You could possibly set up a
Javascript object called frmContent [and call the real form something
different] then add members to it with names corresponding to the
original names, pointing to the actual controls with mangled names
inserted as above.

Trouble with Multiple Master Pages in ASP.NET 2.0

I am writing an ASP.NET 2.0 application that uses more than one master page.
Currently, there are two pages, Freedom1.master and Freedom2.master. I have
no problems with Freedom1.master. However, I am having problems with
Freedom2.master.
The first problem is I sometimes get the following error when I build the
site.
The type 'Freedom2' exists in both
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\freedomlincwebsite\ae6160cc\fecd2e
a4\App_Web_ammoxc8r.dll' and
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\freedomlincwebsite\ae6160cc\fecd2e
a4\App_Web_fxnhzrev.dll'
The error appears for each page built using Freedom2.master.
The second problem occurs at runtime for statments like the following.
protected void Page_Load(object sender, EventArgs e)
{
Freedom2 master = (Freedom2)Master;
master.Page.Header.Title = "Freedom LINC Registration";Your code looks a bit confusing, you seem to be declaring an object called
master of type freedom2 and initialising it with the value contained in it's
self cast as a type freedom2. What are trying to do with that code?
"EagleRed@.HighFlyingBirds.com" wrote:

> I am writing an ASP.NET 2.0 application that uses more than one master pag
e.
> Currently, there are two pages, Freedom1.master and Freedom2.master. I ha
ve
> no problems with Freedom1.master. However, I am having problems with
> Freedom2.master.
> The first problem is I sometimes get the following error when I build the
> site.
> The type 'Freedom2' exists in both
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2e
a4\App_Web_ammoxc8r.dll' and
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2e
a4\App_Web_fxnhzrev.dll'
> The error appears for each page built using Freedom2.master.
> The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
> .
> .
> .
> The error message states that there is a failure to cast an infinite integ
er
> to the type, Freedom2.
> What is going on? How do I address these issues? These problems are
> intermittent but significant.
> Any input is appreciated.
> Thank you,
> EagleRed
>
>
In article <31042077-F0EC-49B9-90D7-C782AEAE5187@.microsoft.com>,
"EagleRed@.HighFlyingBirds.com"
<EagleRedHighFlyingBirdscom@.discussions.microsoft.com> writes
>I am writing an ASP.NET 2.0 application that uses more than one master page
.
>Currently, there are two pages, Freedom1.master and Freedom2.master. I hav
e
>no problems with Freedom1.master. However, I am having problems with
>Freedom2.master.
>The first problem is I sometimes get the following error when I build the
>site.
>The type 'Freedom2' exists in both
>'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2e
a4\App_Web_ammoxc8r.dll' and
>'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2e
a4\App_Web_fxnhzrev.dll'
>The error appears for each page built using Freedom2.master.
Try stopping the server, then deleting the files in the temporary
ASP.NET files folder. Then restart the server and try again. I have seen
this cure this problem.

>The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
<snip>
Why are you doing it this way? Title is a standard property of the page,
even when master pages are used, so you can simply do...
Page.Header.Title = "Freedom LINC Registration";
More to the point, if you are setting the title to a fixed string, just
set it in the Page directive of the .aspx file instead of in code. As I
understand it, this gets compiled with the page, so will be a teensy
weensy bit faster too.
HTH
Alan Silver
(anything added below this line is nothing to do with me)
Needed or non needed code I have the same problem:
I usually cast master in order to hide or show some components / parts
of page. Anyhow why I want to cast master page is not an issue here.
The issue is why this cast may or may not fail.
My findings are that:
- I assume that in place compilation creates 2 copies of assembly,
- killing w3wp usually helps (if it doesn't delete asp.net tmp
folders/files),
- it may happens only after some compilation was made (after changes in
files, etc...).
I belive that, precompiled deployment is safer regarding this
problem...
I would like some more info about that problem.
bye,
D

Trouble with Multiple Master Pages in ASP.NET 2.0

I am writing an ASP.NET 2.0 application that uses more than one master page.
Currently, there are two pages, Freedom1.master and Freedom2.master. I have
no problems with Freedom1.master. However, I am having problems with
Freedom2.master.

The first problem is I sometimes get the following error when I build the
site.

The type 'Freedom2' exists in both
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'

The error appears for each page built using Freedom2.master.

The second problem occurs at runtime for statments like the following.

protected void Page_Load(object sender, EventArgs e)
{

Freedom2 master = (Freedom2)Master;
master.Page.Header.Title = "Freedom LINC Registration";Your code looks a bit confusing, you seem to be declaring an object called
master of type freedom2 and initialising it with the value contained in it's
self cast as a type freedom2. What are trying to do with that code?

"EagleRed@.HighFlyingBirds.com" wrote:

> I am writing an ASP.NET 2.0 application that uses more than one master page.
> Currently, there are two pages, Freedom1.master and Freedom2.master. I have
> no problems with Freedom1.master. However, I am having problems with
> Freedom2.master.
> The first problem is I sometimes get the following error when I build the
> site.
> The type 'Freedom2' exists in both
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'
> The error appears for each page built using Freedom2.master.
> The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
> .
> .
> .
> The error message states that there is a failure to cast an infinite integer
> to the type, Freedom2.
> What is going on? How do I address these issues? These problems are
> intermittent but significant.
> Any input is appreciated.
> Thank you,
> EagleRed
>
In this case I am changing the title of the page with the statement,

master.Page.Header.Title = "Freedom LINC Registration";

There are other occasions I wish to access properties on the master page
from the aspx page that uses it. For example to change the href on a link.

My problem is that I have multiple master pages, e.g. Freedom1. All inherit
from the Master class. Freedom1 derived pages work fine but I am getting
intermittent compilation or runtime errors with Freedom2.

Thanks,
EagleRed

"EagleRed@.HighFlyingBirds.com" wrote:

> I am writing an ASP.NET 2.0 application that uses more than one master page.
> Currently, there are two pages, Freedom1.master and Freedom2.master. I have
> no problems with Freedom1.master. However, I am having problems with
> Freedom2.master.
> The first problem is I sometimes get the following error when I build the
> site.
> The type 'Freedom2' exists in both
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
> 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
> Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'
> The error appears for each page built using Freedom2.master.
> The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
> .
> .
> .
> The error message states that there is a failure to cast an infinite integer
> to the type, Freedom2.
> What is going on? How do I address these issues? These problems are
> intermittent but significant.
> Any input is appreciated.
> Thank you,
> EagleRed
>
In article <31042077-F0EC-49B9-90D7-C782AEAE5187@.microsoft.com>,
"EagleRed@.HighFlyingBirds.com"
<EagleRedHighFlyingBirdscom@.discussions.microsoft.c om> writes
>I am writing an ASP.NET 2.0 application that uses more than one master page.
>Currently, there are two pages, Freedom1.master and Freedom2.master. I have
>no problems with Freedom1.master. However, I am having problems with
>Freedom2.master.
>The first problem is I sometimes get the following error when I build the
>site.
>The type 'Freedom2' exists in both
>'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
>Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _ammoxc8r.dll' and
>'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
>Files\freedomlincwebsite\ae6160cc\fecd2ea4\App_Web _fxnhzrev.dll'
>The error appears for each page built using Freedom2.master.

Try stopping the server, then deleting the files in the temporary
ASP.NET files folder. Then restart the server and try again. I have seen
this cure this problem.

>The second problem occurs at runtime for statments like the following.
> protected void Page_Load(object sender, EventArgs e)
> {
> Freedom2 master = (Freedom2)Master;
> master.Page.Header.Title = "Freedom LINC Registration";
<snip
Why are you doing it this way? Title is a standard property of the page,
even when master pages are used, so you can simply do...

Page.Header.Title = "Freedom LINC Registration";

More to the point, if you are setting the title to a fixed string, just
set it in the Page directive of the .aspx file instead of in code. As I
understand it, this gets compiled with the page, so will be a teensy
weensy bit faster too.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Needed or non needed code I have the same problem:

I usually cast master in order to hide or show some components / parts
of page. Anyhow why I want to cast master page is not an issue here.
The issue is why this cast may or may not fail.
My findings are that:
- I assume that in place compilation creates 2 copies of assembly,
- killing w3wp usually helps (if it doesn't delete asp.net tmp
folders/files),
- it may happens only after some compilation was made (after changes in
files, etc...).

I belive that, precompiled deployment is safer regarding this
problem...

I would like some more info about that problem.

bye,
D

trouble with rollover buttons on master page

asp.net 2.0
Iv'e spent the last 3 or 4 hours trying to get this to work. I'm simply
trying to get rollover buttons to work on my master page.
1. The master page is in the root. "Website1"
2. The images for the buttons are in a subfolder off the root
("Website1\RolloverButtonsImages")
3. There are some pages that user the master that are in subfolders such ase
"Website1\LoggedInUsers"
The above is important because I believe that master pages is part of what's
goofing this up.
I have been using some rollover button code that uses this sort of code:
<a href="http://links.10026.com/?link=Default.aspx" onmouseover="setOverImg('1','');"
onmouseout="setOutImg('1','');" target=""> <img
src="RolloverButtonsImages/button1up.png" border="0" id="button1" vspace="1"
hspace="1"></a>
On my development machine, the only way I was able to get the images to work
properly was to hard code the roote into the paths like this:
<a href="http://links.10026.com/?link=/MySite1/Default.aspx" onmouseover="setOverImg('1','');"
onmouseout="setOutImg('1','');" target=""> <img
src="/MySite1/RolloverButtonsImages/button1up.png" border="0" id="button1"
vspace="1" hspace="1"></a>
That seemed to work ok. But when I moved it to a remote production server
things sort of fell apart and I kind of understand why. So someone told me
that it's probably not a good idea to use the "a href with an img in it"
type of layout for this because the whole ~ for the root can confuse a href
I guess. I'm new at a lot fo this so I guess maybe that's possible. And I
understand the reason NOT to hard code the root into things but that was the
only way i could get thigns to work at all before.
Pretty much EVERYTHING I find online suggests the simplest way to do this is
to instead use asp:imagebutton like this:
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/RolloverButtonsImages/button1up.png"
PostBackUrl="~/Default.aspx" /><br />
and putting some code like this in the Page_Load event:
ImageButton1.Attributes.Add("OnMouseOver",
"this.src='~/RolloverButtonsImages/button1over.png'")
ImageButton1.Attributes.Add("OnMouseOut",
"this.src='~/RolloverButtonsImages/button1up.png'")
Well that didn't work either. The image button markup itself does what I
expect. The image button shows up and when I click it it goes to my default
page regardless of where I am in the site. But the code above that's
supposed to change the image causes screwy behavior. When I mouse over the
image button, the image vanishes and it's replaced by the text "submit
query" on the page. I also tried putting If Not Page.IsPostback around the
above and that didn't help.
I tried all of this and it works on his site but it does NOT work for me on
master page layout I'm dealing with: http://aspalliance.com/317
What seems like should be pretty simple has turned into a nightmare for me.
Could someone give me some clear instructions on the best way to do this
considering all that I've said above? (master pages, subfolders, etc.)? I
need this to work so that the buttons link to the correct url no matter
where I am in the directory tree and so that they also display the correct
images no matter which page is running. Again, I think a big part of the
problem is that the buttons are on the MASTER page. There's got to be a
simple way to deal with this. i just haven't found it. I really don't care
if they're link buttons, image buttons, href's with html buttons or what as
long as it works and works consistently.
Thanks in advance,
Keiththere are a couple things to understand.
1) the master page is a control on the page referencing it, so any
relative url's are relative to the page's location, not the master. (the
browser doesn't know anthing about master pages).
2) the ~/url command (borrowed from unix web servers) is implemented by
asp.net code. on page render any server control with a url property,
asp.net check if the url starts with a "~", if so deteremines the
relative path from the vdir and replaces the "~" with it.
therefore:
<img src="http://pics.10026.com/?src=~/images/img.gif"> no translation done
<img src="http://pics.10026.com/?src=~/images/img.gif" runat="server" /> translation will be done
so you need to add runat=server to your <a> and <img> to get the "~"
support. for javascript you are out of luck, you will need to write your
own, or use hidden images:
<img id="iRollOver1" src="http://pics.10026.com/?src=~/rollover1.gif"
runat="server" style="display:none" />
then in javascript copy the src url. this has the advantage of
precaching the rollover images.
-- bruce (sqlwork.com)
Keith G Hicks wrote:
> asp.net 2.0
> Iv'e spent the last 3 or 4 hours trying to get this to work. I'm simply
> trying to get rollover buttons to work on my master page.
> 1. The master page is in the root. "Website1"
> 2. The images for the buttons are in a subfolder off the root
> ("Website1\RolloverButtonsImages")
> 3. There are some pages that user the master that are in subfolders such a
se
> "Website1\LoggedInUsers"
> The above is important because I believe that master pages is part of what
's
> goofing this up.
> I have been using some rollover button code that uses this sort of code:
> <a href="http://links.10026.com/?link=Default.aspx" onmouseover="setOverImg('1','');"
> onmouseout="setOutImg('1','');" target=""> <img
> src="http://pics.10026.com/?src=RolloverButtonsImages/button1up.png" border="0" id="button1" vspace="
1"
> hspace="1"></a>
> On my development machine, the only way I was able to get the images to wo
rk
> properly was to hard code the roote into the paths like this:
> <a href="http://links.10026.com/?link=/MySite1/Default.aspx" onmouseover="setOverImg('1','');"
> onmouseout="setOutImg('1','');" target=""> <img
> src="http://pics.10026.com/?src=/MySite1/RolloverButtonsImages/button1up.png" border="0" id="button1"
> vspace="1" hspace="1"></a>
> That seemed to work ok. But when I moved it to a remote production server
> things sort of fell apart and I kind of understand why. So someone told me
> that it's probably not a good idea to use the "a href with an img in it"
> type of layout for this because the whole ~ for the root can confuse a hre
f
> I guess. I'm new at a lot fo this so I guess maybe that's possible. And I
> understand the reason NOT to hard code the root into things but that was t
he
> only way i could get thigns to work at all before.
> Pretty much EVERYTHING I find online suggests the simplest way to do this
is
> to instead use asp:imagebutton like this:
> <asp:ImageButton ID="ImageButton1" runat="server"
> ImageUrl="~/RolloverButtonsImages/button1up.png"
> PostBackUrl="~/Default.aspx" /><br />
> and putting some code like this in the Page_Load event:
> ImageButton1.Attributes.Add("OnMouseOver",
> "this.src='~/RolloverButtonsImages/button1over.png'")
> ImageButton1.Attributes.Add("OnMouseOut",
> "this.src='~/RolloverButtonsImages/button1up.png'")
> Well that didn't work either. The image button markup itself does what I
> expect. The image button shows up and when I click it it goes to my defaul
t
> page regardless of where I am in the site. But the code above that's
> supposed to change the image causes screwy behavior. When I mouse over the
> image button, the image vanishes and it's replaced by the text "submit
> query" on the page. I also tried putting If Not Page.IsPostback around the
> above and that didn't help.
> I tried all of this and it works on his site but it does NOT work for me o
n
> master page layout I'm dealing with: http://aspalliance.com/317
> What seems like should be pretty simple has turned into a nightmare for me
.
> Could someone give me some clear instructions on the best way to do this
> considering all that I've said above? (master pages, subfolders, etc.)? I
> need this to work so that the buttons link to the correct url no matter
> where I am in the directory tree and so that they also display the correct
> images no matter which page is running. Again, I think a big part of the
> problem is that the buttons are on the MASTER page. There's got to be a
> simple way to deal with this. i just haven't found it. I really don't care
> if they're link buttons, image buttons, href's with html buttons or what a
s
> long as it works and works consistently.
> Thanks in advance,
> Keith
>
OK. Thanks Bruce. Your explanation about the tilde and runat="server" helped
a lot. But I'm lost on the other end.
Given the code shown below, here's what happens. All the buttons show up
when loading the page. They show up with the "out" image which is of course
correct. When I click one of them it directs to the correct page. That's
fine so far. They also show up and click to the correct pages as expected
when I'm viewing a page that's in a subfolder. So far so good. But the
rollover doesn't do anything. I don't get the "over" image at any time. No
errors, no funny behavior, just no image change.
There are 3 things shown below.
1 - the contents of a javascript file that's supposed to change the
images.
2 - the contents of my masterpage head section.
3 - one of the button definitions.
Here's the contents of the javascript file (which was created by a button
generating tool). The file is named RolloverButtonsImagesMenuScript.js and
is in the root. Notice the first line is var buttonFolder =
"~/RolloverButtonsImages/"; with the tilde (I've tried it without the tilde
as well and other variations I could think of too). I know this code works
generally because when I had this running on my development machien I had
hard coded the root folder name into just about everything. But when I got
to the remote server, things fell apart and I realized that was a mistake.
So here I am.
/*############### js file code begins here ###################*/
/*** SET BUTTON'S FOLDER HERE ***/
var buttonFolder = "~/RolloverButtonsImages/";
/*** SET BUTTONS' FILENAMES HERE ***/
upSources = new
Array("button1up.png","button2up.png","button3up.png","button4up.png","butto
n5up.png","button6up.png","button7up.png","button8up.png","button9up.png","b
utton10up.png","button11up.png");
overSources = new
Array("button1over.png","button2over.png","button3over.png","button4over.png
","button5over.png","button6over.png","button7over.png","button8over.png","b
utton9over.png","button10over.png","button11over.png");
//*** NO MORE SETTINGS BEYOND THIS POINT ***//
totalButtons = upSources.length;
//*** MAIN BUTTONS FUNCTIONS ***//
// PRELOAD MAIN MENU BUTTON IMAGES
function preload() {
for ( x=0; x<totalButtons; x++ ) {
buttonUp = new Image();
buttonUp.src = buttonFolder + upSources[x];
buttonOver = new Image();
buttonOver.src = buttonFolder + overSources[x];
}
}
// SET MOUSEOVER BUTTON
function setOverImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder +
overSources[But-1];
}
// SET MOUSEOUT BUTTON
function setOutImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder +
upSources[But-1];
}
//preload();
/*############### js file code ends here ###################*/
In the HEAD section of my master page I have this:
<head runat="server">
<title>Untitled Page</title>
<script src="http://pics.10026.com/?src=RolloverButtonsImagesMenuScript.js" language="javascript"
type="text/javascript"></script>
<link rel="SHORTCUT ICON" href="http://links.10026.com/?link=favicon.ico">
</head>
Finally, one of the buttons is defined in the master page markup as follows:
<a runat="server" href="http://links.10026.com/?link=~/Default.aspx" onmouseover="setOverImg('1','');"
onmouseout="setOutImg('1','');" target=""> <img runat="server"
src="~/RolloverButtonsImages/button1up.png" border="0" id="button1"
vspace="1" hspace="1"></a><br>
Hope you can help a little more.
Thanks,
Keith
Well I figured something out. I'd still love to know why all the things
below don't work but here's what is more important now. If I use an
asp:Imagebutton and do this:
<asp:ImageButton
ID="ImageButton1"
runat="server"
ImageUrl="~/RolloverButtonsImages/button3up.png"
onmouseover="this.src='~/RolloverButtonsImages/button3over.png'"
onmouseout="this.src='~/RolloverButtonsImages/button3up.png'">
</asp:ImageButton>
I know why the above does not work. The tilde in the "this.src..." does not
get calculated in the page source. I did a view source and asp does not
resolve the tilde. I think I know why but I have no idea how to write the
above so that it DOES work. I tried several variations but got nowhere. If I
take out the tilde and hard code the root, it does work but then I'm back to
my original problem where I don't want to hard code the root.
Thanks,
Keith
"Keith G Hicks" <krh@.comcast.net> wrote in message
news:uiSpE4CkIHA.944@.TK2MSFTNGP05.phx.gbl...
> OK. Thanks Bruce. Your explanation about the tilde and runat="server"
helped
> a lot. But I'm lost on the other end.
> Given the code shown below, here's what happens. All the buttons show up
> when loading the page. They show up with the "out" image which is of
course
> correct. When I click one of them it directs to the correct page. That's
> fine so far. They also show up and click to the correct pages as expected
> when I'm viewing a page that's in a subfolder. So far so good. But the
> rollover doesn't do anything. I don't get the "over" image at any time. No
> errors, no funny behavior, just no image change.
> There are 3 things shown below.
> 1 - the contents of a javascript file that's supposed to change the
> images.
> 2 - the contents of my masterpage head section.
> 3 - one of the button definitions.
>
> Here's the contents of the javascript file (which was created by a button
> generating tool). The file is named RolloverButtonsImagesMenuScript.js and
> is in the root. Notice the first line is var buttonFolder =
> "~/RolloverButtonsImages/"; with the tilde (I've tried it without the
tilde
> as well and other variations I could think of too). I know this code works
> generally because when I had this running on my development machien I had
> hard coded the root folder name into just about everything. But when I got
> to the remote server, things fell apart and I realized that was a mistake.
> So here I am.
> /*############### js file code begins here ###################*/
> /*** SET BUTTON'S FOLDER HERE ***/
> var buttonFolder = "~/RolloverButtonsImages/";
> /*** SET BUTTONS' FILENAMES HERE ***/
> upSources = new
>
Array("button1up.png","button2up.png","button3up.png","button4up.png","butto
>
n5up.png","button6up.png","button7up.png","button8up.png","button9up.png","b
> utton10up.png","button11up.png");
> overSources = new
>
Array("button1over.png","button2over.png","button3over.png","button4over.png
>
","button5over.png","button6over.png","button7over.png","button8over.png","b
> utton9over.png","button10over.png","button11over.png");
> //*** NO MORE SETTINGS BEYOND THIS POINT ***//
> totalButtons = upSources.length;
> //*** MAIN BUTTONS FUNCTIONS ***//
> // PRELOAD MAIN MENU BUTTON IMAGES
> function preload() {
> for ( x=0; x<totalButtons; x++ ) {
> buttonUp = new Image();
> buttonUp.src = buttonFolder + upSources[x];
> buttonOver = new Image();
> buttonOver.src = buttonFolder + overSources[x];
> }
> }
> // SET MOUSEOVER BUTTON
> function setOverImg(But, ID) {
> document.getElementById('button' + But + ID).src = buttonFolder +
> overSources[But-1];
> }
> // SET MOUSEOUT BUTTON
> function setOutImg(But, ID) {
> document.getElementById('button' + But + ID).src = buttonFolder +
> upSources[But-1];
> }
> //preload();
> /*############### js file code ends here ###################*/
> In the HEAD section of my master page I have this:
> <head runat="server">
> <title>Untitled Page</title>
> <script src="http://pics.10026.com/?src=RolloverButtonsImagesMenuScript.js" language="javascript"
> type="text/javascript"></script>
> <link rel="SHORTCUT ICON" href="http://links.10026.com/?link=favicon.ico">
> </head>
>
> Finally, one of the buttons is defined in the master page markup as
follows:
> <a runat="server" href="http://links.10026.com/?link=~/Default.aspx" onmouseover="setOverImg('1','');"
> onmouseout="setOutImg('1','');" target=""> <img runat="server"
> src="http://pics.10026.com/?src=~/RolloverButtonsImages/button1up.png" border="0" id="button1"
> vspace="1" hspace="1"></a><br>
>
> Hope you can help a little more.
> Thanks,
> Keith
>
>
Well I solved this finally. Can't believe it was that hard and nobody said
anything about how to resovle the url based on ~ in the "this.src..." code.
So I changed everything to ImageButtons:
<asp:ImageButton
ID="imgbtnDefault"
runat="server"
CausesValidation="false"
ImageUrl="~/RolloverButtonsImages/button1up.png"
PostBackUrl="~/Default.aspx"
BorderColor="white"
BorderStyle="solid"
BorderWidth="1px">
</asp:ImageButton>
Then in my pages Page_Load event handler I have this:
imgbtnDefault.Attributes.Add("onMouseOver", "src='" &
ResolveUrl("~/RolloverButtonsImages/button1over.png").ToString() & "'")
imgbtnDefault.Attributes.Add("onMouseOut", "src='" &
ResolveUrl("~/RolloverButtonsImages/button1up.png").ToString() & "'")
Works like a peach no matter whether it's on my development machien or in
production remote server and also handles it regardless of what foler the
page I'm on is in.
My only qualm is that the pages "view source" now shows the actual folder
name for the root. Not sure if that's a security issue or not. I'd be
anxious to hear if it is or not.
Keith