how to attach javscript to a ASP:BUTTON

D

Darrel

I have an asp button I want to apply some javascript to.

I have this in the page head:

<script type="text/javascript">
function myOnSubmitEventHandler() {
document.getElementById('editor1').EscapeUNICODE = true;
document.getElementById('xhtml1').value =
document.getElementById('editor1').value;
}
</script>


and this on the page:

<asp:Button onclick="myOnSubmitEventHandler()" id=Button_Save
runat="server" Text="Save Changes">


But this returns an error of:


Compiler Error Message: BC30456: 'myOnSubmitEventHandler' is not a member of
'ASP.editPage_aspx'.

Do I have to do something to 'register' the javascript?

-Darrel
 
D

Darrel

Yeah check this site for details:-

Ah...OK, not so hard:

Button_Save.Attributes.Add("onclick", "myOnSubmitEventHandler();")

Got time for a follow-up?

This javascript is supposed to take the text from an OBJECT (x-standard html
editor) and input it into a textarea that I can then grab via the
codebehind.
The problem is that it doesn't work. Is thie issue that the javascript can't
execute in time for the text to be placed in the textarea before it get's
send back via the postback?

-Darrel
 
D

Darrel

This javascript is supposed to take the text from an OBJECT (x-standard
html editor) and input it into a textarea that I can then grab via the
codebehind.

nevermind...USER ERROR! ;o)

-Darrel
 
G

Guest

So is it working now?


Darrel said:
Ah...OK, not so hard:

Button_Save.Attributes.Add("onclick", "myOnSubmitEventHandler();")

Got time for a follow-up?

This javascript is supposed to take the text from an OBJECT (x-standard html
editor) and input it into a textarea that I can then grab via the
codebehind.
The problem is that it doesn't work. Is thie issue that the javascript can't
execute in time for the text to be placed in the textarea before it get's
send back via the postback?

-Darrel
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top