Adding "onunload" JavaScript event handler to body in code-behind



Hi,

I am trying to programatically add an "onunload" event handler to the "body" tag of an ASPX page. I am doing this from a Custom Control located on this page.

To do this, I added "runat=server" to the body tag, which provides me access to it in the code-behind through a HtmlControl. I can then manipulate the Attributes collection, which is what I needed. So far so good.

However, I found out that "runat=server" generates a compilation error (CS1012: Too many characters in character literal) if the "body" tag already has an onunload event handler (in the ASPX code). This is a problem, because I wish that the user of my custom control be free to specify event handlers in the body tag, and my control should simply add its own.

So the question is: Is there a way to use "runat=server" on a body tag with an onunload event handler?

I am using the framework 1.1.

Unfortunately, there are no "RegisterEndScript" methods (similar to "RegisterStartupScript") in the Page class ;-)

Thanks,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
.



Relevant Pages

  • Re: How to modify label.text in a dynamically generated label in VB.net
    ... Your event handler will go something like this: ... If _tag IsNot Nothing Then ... Private Function FindControl(ByVal start As Control, ByVal type as Type, ... When any one of you dynamic CheckBoxes is clicked, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: "modern" javascript...
    ... Looking in the source to edit jspf, include, and tag files, or PHP ... As I said before, the event handler attribute ... True if the `script' element is the child of the `head' element. ... ISTM the example showed your idea of a "bottom script" quite well. ...
    (comp.lang.javascript)
  • Re: Control ID: ctl00_ctl00
    ... Public Overloads Overrides Sub RenderBeginTag(ByVal writer As ... Now my custom control child controls are wrapped inside a tag. ... The ClientID is the unique ID sent to the web client. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Can I Use HTML Text Writer i a Custom Control to Render the Section?
    ... >I would like to create a custom control that generates everything that will ... > But can I do so since the control would not be withing a tag in the ... > Frank K. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can I Use HTML Text Writer i a Custom Control to Render the Section?
    ... the information in the head section of the returned HTML. ... >I would like to create a custom control that generates everything that will ... > But can I do so since the control would not be withing a tag in the ...
    (microsoft.public.dotnet.languages.csharp)