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

F

Friso Wiskerke

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
 
P

Paul Henderson

Another strange thing: suddenly there's a new said:
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.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top