Writing single client script block for mutiple controls

Discussion in 'ASP .Net Building Controls' started by Jason Barnett, Jun 9, 2006.

  1. I'm using .NET 1.1 and I've created a server control that writes javascript
    to the output writer. The control works great, except when I add additional
    controls. The problem is that each control writes the same javascript block,
    which causes a stack overflow when it is executed.

    Could someone tell me how I may write the javascript to the page only once,
    regardless of how many controls are dropped on the web form?
     
    Jason Barnett, Jun 9, 2006
    #1
    1. Advertising

  2. In the RegisterClientScriptBlock method, what are you using as the key (the
    first parameter)?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Jason Barnett" <> wrote in message
    news:D...
    > I'm using .NET 1.1 and I've created a server control that writes
    > javascript
    > to the output writer. The control works great, except when I add
    > additional
    > controls. The problem is that each control writes the same javascript
    > block,
    > which causes a stack overflow when it is executed.
    >
    > Could someone tell me how I may write the javascript to the page only
    > once,
    > regardless of how many controls are dropped on the web form?
     
    Nathan Sokalski, Jun 9, 2006
    #2
    1. Advertising

  3. I'm not using the RegisterClientScriptBlock method. From what I've read,
    that is a method on the ClientScriptManager class and is only available in
    ..NET 2 or higher. Is there something comparable in .NET 1.1?

    I'm currently writing the script as plain text using output.Write method
    within the Render method.


    "Nathan Sokalski" wrote:

    > In the RegisterClientScriptBlock method, what are you using as the key (the
    > first parameter)?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Jason Barnett" <> wrote in message
    > news:D...
    > > I'm using .NET 1.1 and I've created a server control that writes
    > > javascript
    > > to the output writer. The control works great, except when I add
    > > additional
    > > controls. The problem is that each control writes the same javascript
    > > block,
    > > which causes a stack overflow when it is executed.
    > >
    > > Could someone tell me how I may write the javascript to the page only
    > > once,
    > > regardless of how many controls are dropped on the web form?

    >
    >
    >
     
    Jason Barnett, Jun 9, 2006
    #3
  4. Ok, I now see where I made one mistake. I did a search on
    RegisterClientScriptBlock and found that it is a method on the Page class
    (although, it does not appear in intellisense). I modified my code to use
    the RegisterClientScriptBlock method in conjunction to the
    IsClientScriptBlockRegistered method, but multiple blocks are still being
    written to the page.

    I'm using a constant as the key (ex: "MyClientScript").


    "Jason Barnett" wrote:

    > I'm not using the RegisterClientScriptBlock method. From what I've read,
    > that is a method on the ClientScriptManager class and is only available in
    > .NET 2 or higher. Is there something comparable in .NET 1.1?
    >
    > I'm currently writing the script as plain text using output.Write method
    > within the Render method.
    >
    >
    > "Nathan Sokalski" wrote:
    >
    > > In the RegisterClientScriptBlock method, what are you using as the key (the
    > > first parameter)?
    > > --
    > > Nathan Sokalski
    > >
    > > http://www.nathansokalski.com/
    > >
    > > "Jason Barnett" <> wrote in message
    > > news:D...
    > > > I'm using .NET 1.1 and I've created a server control that writes
    > > > javascript
    > > > to the output writer. The control works great, except when I add
    > > > additional
    > > > controls. The problem is that each control writes the same javascript
    > > > block,
    > > > which causes a stack overflow when it is executed.
    > > >
    > > > Could someone tell me how I may write the javascript to the page only
    > > > once,
    > > > regardless of how many controls are dropped on the web form?

    > >
    > >
    > >
     
    Jason Barnett, Jun 9, 2006
    #4
  5. I am starting to wonder if the problem lies within the script block itself...
    here is an example of what I'd like written out only once. Does it matter
    that it is linked to an external .js file?

    <script src="javascrip/myControl.js" type="text/javascript"></script>


    "Nathan Sokalski" wrote:

    > In the RegisterClientScriptBlock method, what are you using as the key (the
    > first parameter)?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Jason Barnett" <> wrote in message
    > news:D...
    > > I'm using .NET 1.1 and I've created a server control that writes
    > > javascript
    > > to the output writer. The control works great, except when I add
    > > additional
    > > controls. The problem is that each control writes the same javascript
    > > block,
    > > which causes a stack overflow when it is executed.
    > >
    > > Could someone tell me how I may write the javascript to the page only
    > > once,
    > > regardless of how many controls are dropped on the web form?

    >
    >
    >
     
    Jason Barnett, Jun 9, 2006
    #5
  6. Ok, I got it. I was trying to use the RegisterClientScriptBlock method
    during the Render event. When I used it during the PreRender event it began
    working.


    "Jason Barnett" wrote:

    > I am starting to wonder if the problem lies within the script block itself...
    > here is an example of what I'd like written out only once. Does it matter
    > that it is linked to an external .js file?
    >
    > <script src="javascrip/myControl.js" type="text/javascript"></script>
    >
    >
    > "Nathan Sokalski" wrote:
    >
    > > In the RegisterClientScriptBlock method, what are you using as the key (the
    > > first parameter)?
    > > --
    > > Nathan Sokalski
    > >
    > > http://www.nathansokalski.com/
    > >
    > > "Jason Barnett" <> wrote in message
    > > news:D...
    > > > I'm using .NET 1.1 and I've created a server control that writes
    > > > javascript
    > > > to the output writer. The control works great, except when I add
    > > > additional
    > > > controls. The problem is that each control writes the same javascript
    > > > block,
    > > > which causes a stack overflow when it is executed.
    > > >
    > > > Could someone tell me how I may write the javascript to the page only
    > > > once,
    > > > regardless of how many controls are dropped on the web form?

    > >
    > >
    > >
     
    Jason Barnett, Jun 9, 2006
    #6
  7. Jason Barnett

    sam Guest

    Watch out for this method. After 8 different calls it will start
    outputing the script tags in a random order with respect to what order
    the method executes in the page. this is because microsoft uses the
    retarded HybridDictionary class.

    Should'nt make a difference unless you require the script tags to be
    output in a specific order.
     
    sam, Jun 17, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    1
    Views:
    522
    =?Utf-8?B?UmljaA==?=
    Apr 29, 2005
  2. varadha
    Replies:
    3
    Views:
    462
    Kevin Goodsell
    Sep 9, 2003
  3. Senthil

    Mutiple JVM in Single Os

    Senthil, Feb 9, 2007, in forum: Java
    Replies:
    4
    Views:
    699
    Chris Uppal
    Feb 11, 2007
  4. Lakshmi Narayanan.R

    Mutiple server forms in single asp.net page

    Lakshmi Narayanan.R, Jul 22, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    135
    Lakshmi Narayanan.R
    Jul 23, 2004
  5. Water Cooler v2
    Replies:
    2
    Views:
    511
    Water Cooler v2
    Apr 18, 2006
Loading...

Share This Page