Master Pages and Javascript

M

MonkeeX

Hi,

I'm trying to convert my normal ASP.NET site to one which uses master
pages. I have a separate js file which sets a HTML control on the form
as follows:-

form1.ctllname.value = mainDiv.HTML;

Of course the form does not exist anymore in this file as it is now as
asp:content page and I get the wrror message:-

'form1 is undefined'

How can I set this same control in the new context?

Seems straight forward but I can't crack it.


Thanks,
MonkeyBoy
 
M

Mark Rae

Hi,

I'm trying to convert my normal ASP.NET site to one which uses master
pages. I have a separate js file which sets a HTML control on the form
as follows:-

form1.ctllname.value = mainDiv.HTML;

Of course the form does not exist anymore in this file as it is now as
asp:content page and I get the wrror message:-

'form1 is undefined'

How can I set this same control in the new context?

Seems straight forward but I can't crack it.


When your page is loaded, do a View Source and see how the various objects
have been renamed...

Then, maybe try something like this:

<script type="text/javascript">
document.getElementById('<%=ctlname.ClientID%>').value = mainDiv.HTML;
</script>
 
M

MonkeeX

Hi,

I'm trying to convert my normal ASP.NET site to one which uses master
pages. I have a separate js file which sets a HTML control on the form
as follows:-

form1.ctllname.value = mainDiv.HTML;

Of course the form does not exist anymore in this file as it is now as
asp:content page and I get the wrror message:-

'form1 is undefined'

How can I set this same control in the new context?

Seems straight forward but I can't crack it.

Thanks,
MonkeyBoy

Having been thinking about this on the wrong level for sometime I
finally came to my senses (tip: take breaks). You just need to do a
getElementById as normal.

var ctllname= document.getElementById("ctllname");
ctllname.value = mainDiv.HTML;

Cheers,
MonkeyBoy
 
M

MonkeeX

When your page is loaded, do a View Source and see how the various objects
have been renamed...

Then, maybe try something like this:

<script type="text/javascript">
document.getElementById('<%=ctlname.ClientID%>').value = mainDiv.HTML;
</script>- Hide quoted text -

- Show quoted text -

Thanks Mark, I got it working using my version above. Cheers!
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top