how to attach javscript to a ASP:BUTTON

  • Thread starter Thread starter Darrel
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top