Emitting Client Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed Courtenay

    Emitting Client Script


    Reposting here as you can practically see the tumbleweed blow by in
    microsoft.publi c.dotnet.framew ork.aspnet.webc ontrols....

    I've got a very simple custom control that requires a small section of
    JavaScript to function at the client - nothing out of the ordinary.

    In the overridden RenderContents method of my custom control I check
    whether the required client script block has been registered with
    Page.ClientScri pt.IsClientScri ptBlockRegister ed() and if not, register
    it with Page.ClientScri pt.RegisterClie ntScriptBlock()

    If I place the custom control on a web form, the script gets injected
    into the page as expected and works as it should.

    If, however, the control is placed onto a Master page the script doesn't
    get injected and therefore the control fails to work; why is this
    behaving differently when the control is placed on a Master page, and
    what do I have to do to get it to work?
  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: Emitting Client Script

    RenderContents is the wrong time to register the script. as the script block
    comes before the controls html, its too late to render it after you have
    rendered the content. Suprised your code ever worked.

    move the RegisterClientS criptBlock to OnPreRender where it belongs.


    -- bruce (sqlwork.com)


    "Ed Courtenay" wrote:
    >
    Reposting here as you can practically see the tumbleweed blow by in
    microsoft.publi c.dotnet.framew ork.aspnet.webc ontrols....
    >
    I've got a very simple custom control that requires a small section of
    JavaScript to function at the client - nothing out of the ordinary.
    >
    In the overridden RenderContents method of my custom control I check
    whether the required client script block has been registered with
    Page.ClientScri pt.IsClientScri ptBlockRegister ed() and if not, register
    it with Page.ClientScri pt.RegisterClie ntScriptBlock()
    >
    If I place the custom control on a web form, the script gets injected
    into the page as expected and works as it should.
    >
    If, however, the control is placed onto a Master page the script doesn't
    get injected and therefore the control fails to work; why is this
    behaving differently when the control is placed on a Master page, and
    what do I have to do to get it to work?
    >

    Comment

    • Ed Courtenay

      #3
      Re: Emitting Client Script

      bruce barker wrote:
      RenderContents is the wrong time to register the script. as the script block
      comes before the controls html, its too late to render it after you have
      rendered the content. Suprised your code ever worked.
      >
      move the RegisterClientS criptBlock to OnPreRender where it belongs.
      >
      >
      -- bruce (sqlwork.com)
      >
      How the hell did I miss that? *blush*

      It's strange what you miss when it's staring you straight in the face!

      >
      "Ed Courtenay" wrote:
      >
      >Reposting here as you can practically see the tumbleweed blow by in
      >microsoft.publ ic.dotnet.frame work.aspnet.web controls....
      >>
      >I've got a very simple custom control that requires a small section of
      >JavaScript to function at the client - nothing out of the ordinary.
      >>
      >In the overridden RenderContents method of my custom control I check
      >whether the required client script block has been registered with
      >Page.ClientScr ipt.IsClientScr iptBlockRegiste red() and if not, register
      >it with Page.ClientScri pt.RegisterClie ntScriptBlock()
      >>
      >If I place the custom control on a web form, the script gets injected
      >into the page as expected and works as it should.
      >>
      >If, however, the control is placed onto a Master page the script doesn't
      >get injected and therefore the control fails to work; why is this
      >behaving differently when the control is placed on a Master page, and
      >what do I have to do to get it to work?
      >>

      Comment

      Working...