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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top