Need Help with Registering Client Scripts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Wood

    Need Help with Registering Client Scripts

    I'm trying to duplicate an HTML sample I have using my ASP.NET pages.

    The sample contains the following within the <headtag:

    <script type="text/javascript" src="flashobjec t.js"></script>
    <script type="text/javascript">
    // <![CDATA[
    var args = new Object();
    var query = location.search .substring(1);
    // Get query string
    var pairs = query.split( "," );
    // Break at comma
    for ( var i = 0; i < pairs.length; i++ )
    {
    var pos = pairs[i].indexOf('=');
    if( pos == -1 )
    {
    continue; // Look for "name=value "
    }
    var argname = pairs[i].substring( 0, pos ); // If not found, skip
    var value = pairs[i].substring( pos + 1 ); // Extract the name
    args[argname] = unescape( value ); // Extract the value
    }
    // ]]>
    </script>

    To do this the ASP.NET way, I added the following code to my Page_Load
    handler:

    if (!Page.ClientSc ript.IsClientSc riptBlockRegist ered("FlashObje ct"))
    Page.ClientScri pt.RegisterClie ntScriptInclude (typeof(Page),
    "FlashObjec t", "flashobject.js ");

    if (!Page.ClientSc ript.IsStartupS criptRegistered ("PrepVideo" ))
    Page.ClientScri pt.RegisterStar tupScript(typeo f(Page), "PrepVideo" ,
    "var args=new Object();" +
    "var query=location. search.substrin g(1);" +
    "var pairs=query.spl it(',');" +
    "for (var i=0;i < pairs.length;i+ +){" +
    "var pos=pairs[i].indexOf('=');" +
    "if (pos==-1) continue;" +
    "var argname=pairs[i].substring(0,po s);" +
    "var value=pairs[i].substring(pos + 1);" +
    "args[argname]=unescape(value );}", true);
    }

    I assume the second script is a start-up script since it is not a callable
    function. So this seems like it should work but it does not duplicate the
    functionality of the sample.

    Looking at the HTML produced, I see neither registered scripts are placed
    within the <headtag. So instead of calling RegisterClientS criptInclude and
    RegisterStartup Script, I instead forced these scripts into the <headtag
    and they WORKED!!

    Unfortunately, I need to put this in a control that really should register
    the scripts in an organized way.

    Is there any way to register a script such that it is inserted within the
    <headtag? Or perhaps there's something else I'm missing?

    Thanks.

    Jonathan

  • Munna

    #2
    Re: Need Help with Registering Client Scripts

    On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
    I'm trying to duplicate an HTML sample I have using my ASP.NET pages.
    >
    The sample contains the following within the <headtag:
    >
       <script type="text/javascript" src="flashobjec t.js"></script>
       <script type="text/javascript">
          // <![CDATA[
          var args = new Object();
          var query = location.search .substring(1);
          // Get query string
          var pairs = query.split( "," );
          // Break at comma
          for ( var i = 0; i < pairs.length; i++ )
          {
             var pos = pairs[i].indexOf('=');
             if( pos == -1 )
             {
                continue; // Look for "name=value "
             }
             var argname = pairs[i].substring( 0, pos ); // If notfound, skip
             var value = pairs[i].substring( pos + 1 ); // Extractthe name
             args[argname] = unescape( value ); // Extract the value
          }
          // ]]>
       </script>
    >
    To do this the ASP.NET way, I added the following code to my Page_Load
    handler:
    >
      if (!Page.ClientSc ript.IsClientSc riptBlockRegist ered("FlashObje ct"))
       Page.ClientScri pt.RegisterClie ntScriptInclude (typeof(Page),
    "FlashObjec t", "flashobject.js ");
    >
      if (!Page.ClientSc ript.IsStartupS criptRegistered ("PrepVideo" ))
       Page.ClientScri pt.RegisterStar tupScript(typeo f(Page), "PrepVideo" ,
        "var args=new Object();" +
        "var query=location. search.substrin g(1);" +
        "var pairs=query.spl it(',');" +
        "for (var i=0;i < pairs.length;i+ +){" +
        "var pos=pairs[i].indexOf('=');" +
        "if (pos==-1) continue;" +
        "var argname=pairs[i].substring(0,po s);" +
        "var value=pairs[i].substring(pos + 1);" +
        "args[argname]=unescape(value );}", true);
     }
    >
    I assume the second script is a start-up script since it is not a callable
    function. So this seems like it should work but it does not duplicate the
    functionality of the sample.
    >
    Looking at the HTML produced, I see neither registered scripts are placed
    within the <headtag. So instead of calling RegisterClientS criptInclude and
    RegisterStartup Script, I instead forced these scripts into the <headtag
    and they WORKED!!
    >
    Unfortunately, I need to put this in a control that really should register
    the scripts in an organized way.
    >
    Is there any way to register a script such that it is inserted within the
    <headtag? Or perhaps there's something else I'm missing?
    >
    Thanks.
    >
    Jonathan
    Hi

    use this method to check wheiter script already added or not...

    Page.ClientScri pt.IsClientScri ptBlockRegister ed();

    and to register use

    Page.ClientScri pt.RegisterClie ntScriptBlock() ;

    Best of luck

    Munna



    Comment

    • Jonathan Wood

      #3
      Re: Need Help with Registering Client Scripts

      use this method to check wheiter script already added or not...
      >
      Page.ClientScri pt.IsClientScri ptBlockRegister ed();
      >
      and to register use
      >
      Page.ClientScri pt.RegisterClie ntScriptBlock() ;
      Well, thanks. But not only does this not address the problem I've described,
      you're telling me to do exactly what the code I posted shows I was already
      doing.

      --
      Jonathan Wood
      SoftCircuits Programming


      "Munna" <munnaonc@gmail .comwrote in message
      news:085ec46d-cee3-4b9b-9e8a-1c8fc7d3368b@j1 g2000prb.google groups.com...
      On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
      I'm trying to duplicate an HTML sample I have using my ASP.NET pages.
      >
      The sample contains the following within the <headtag:
      >
      <script type="text/javascript" src="flashobjec t.js"></script>
      <script type="text/javascript">
      // <![CDATA[
      var args = new Object();
      var query = location.search .substring(1);
      // Get query string
      var pairs = query.split( "," );
      // Break at comma
      for ( var i = 0; i < pairs.length; i++ )
      {
      var pos = pairs[i].indexOf('=');
      if( pos == -1 )
      {
      continue; // Look for "name=value "
      }
      var argname = pairs[i].substring( 0, pos ); // If not found, skip
      var value = pairs[i].substring( pos + 1 ); // Extract the name
      args[argname] = unescape( value ); // Extract the value
      }
      // ]]>
      </script>
      >
      To do this the ASP.NET way, I added the following code to my Page_Load
      handler:
      >
      if (!Page.ClientSc ript.IsClientSc riptBlockRegist ered("FlashObje ct"))
      Page.ClientScri pt.RegisterClie ntScriptInclude (typeof(Page),
      "FlashObjec t", "flashobject.js ");
      >
      if (!Page.ClientSc ript.IsStartupS criptRegistered ("PrepVideo" ))
      Page.ClientScri pt.RegisterStar tupScript(typeo f(Page), "PrepVideo" ,
      "var args=new Object();" +
      "var query=location. search.substrin g(1);" +
      "var pairs=query.spl it(',');" +
      "for (var i=0;i < pairs.length;i+ +){" +
      "var pos=pairs[i].indexOf('=');" +
      "if (pos==-1) continue;" +
      "var argname=pairs[i].substring(0,po s);" +
      "var value=pairs[i].substring(pos + 1);" +
      "args[argname]=unescape(value );}", true);
      }
      >
      I assume the second script is a start-up script since it is not a callable
      function. So this seems like it should work but it does not duplicate the
      functionality of the sample.
      >
      Looking at the HTML produced, I see neither registered scripts are placed
      within the <headtag. So instead of calling RegisterClientS criptInclude
      and
      RegisterStartup Script, I instead forced these scripts into the <headtag
      and they WORKED!!
      >
      Unfortunately, I need to put this in a control that really should register
      the scripts in an organized way.
      >
      Is there any way to register a script such that it is inserted within the
      <headtag? Or perhaps there's something else I'm missing?
      >
      Thanks.
      >
      Jonathan

      Comment

      • Munna

        #4
        Re: Need Help with Registering Client Scripts

        On Jun 7, 11:55 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
        use this method to check wheiter script already added or not...
        >
        Page.ClientScri pt.IsClientScri ptBlockRegister ed();
        >
        and to register use
        >
        Page.ClientScri pt.RegisterClie ntScriptBlock() ;
        >
        Well, thanks. But not only does this not address the problem I've described,
        you're telling me to do exactly what the code I posted shows I was already
        doing.
        >
        --
        Jonathan Wood
        SoftCircuits Programminghttp ://www.softcircuit s.com
        >
        "Munna" <munna...@gmail .comwrote in message
        >
        news:085ec46d-cee3-4b9b-9e8a-1c8fc7d3368b@j1 g2000prb.google groups.com...
        On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
        >
        I'm trying to duplicate an HTML sample I have using my ASP.NET pages.
        >
        The sample contains the following within the <headtag:
        >
        <script type="text/javascript" src="flashobjec t.js"></script>
        <script type="text/javascript">
        // <![CDATA[
        var args = new Object();
        var query = location.search .substring(1);
        // Get query string
        var pairs = query.split( "," );
        // Break at comma
        for ( var i = 0; i < pairs.length; i++ )
        {
        var pos = pairs[i].indexOf('=');
        if( pos == -1 )
        {
        continue; // Look for "name=value "
        }
        var argname = pairs[i].substring( 0, pos ); // If not found, skip
        var value = pairs[i].substring( pos + 1 ); // Extract the name
        args[argname] = unescape( value ); // Extract the value
        }
        // ]]>
        </script>
        >
        To do this the ASP.NET way, I added the following code to my Page_Load
        handler:
        >
        if (!Page.ClientSc ript.IsClientSc riptBlockRegist ered("FlashObje ct"))
        Page.ClientScri pt.RegisterClie ntScriptInclude (typeof(Page),
        "FlashObjec t", "flashobject.js ");
        >
        if (!Page.ClientSc ript.IsStartupS criptRegistered ("PrepVideo" ))
        Page.ClientScri pt.RegisterStar tupScript(typeo f(Page), "PrepVideo" ,
        "var args=new Object();" +
        "var query=location. search.substrin g(1);" +
        "var pairs=query.spl it(',');" +
        "for (var i=0;i < pairs.length;i+ +){" +
        "var pos=pairs[i].indexOf('=');" +
        "if (pos==-1) continue;" +
        "var argname=pairs[i].substring(0,po s);" +
        "var value=pairs[i].substring(pos + 1);" +
        "args[argname]=unescape(value );}", true);
        }
        >
        I assume the second script is a start-up script since it is not a callable
        function. So this seems like it should work but it does not duplicate the
        functionality of the sample.
        >
        Looking at the HTML produced, I see neither registered scripts are placed
        within the <headtag. So instead of calling RegisterClientS criptInclude
        and
        RegisterStartup Script, I instead forced these scripts into the <headtag
        and they WORKED!!
        >
        Unfortunately, I need to put this in a control that really should register
        the scripts in an organized way.
        >
        Is there any way to register a script such that it is inserted within the
        <headtag? Or perhaps there's something else I'm missing?
        >
        Thanks.
        >
        Jonathan
        Hi Jonathan

        "RegisterStartu pScript" add scripts just before the end of "</body>"
        tag..
        and "RegisterClient ScriptBlock" add script inside the form as far as i
        seen so far..
        well since you need the script in the head block here is a work around
        i found and worked for me...

        i added a literal control in size the head tag

        <head id="Myhead" runat="server">
        <title>Untitl ed Page</title>
        <asp:Literal ID="ScriptSourc e" runat="server"> </asp:Literal>
        </head>

        and in page load event i did this

        ScriptSource.Te xt = "<script>window .alert('Worked okay');</script>";

        surely you need to do some coding to adjust what you want to insert in
        head...

        Best of luck

        Munna



        Comment

        • Jonathan Wood

          #5
          Re: Need Help with Registering Client Scripts

          I figured this out. Turns out that it is not necessary for these scripts to
          be within the <headtag. I don't understand exactly how they are used but
          if I don't register the second script as a startup script and instead
          register it as a regular client script block, it appears to work just fine.
          Thanks.

          --
          Jonathan Wood
          SoftCircuits Programming


          "Munna" <munnaonc@gmail .comwrote in message
          news:d5b51d82-a355-4e76-af9f-759f64ea4271@z2 4g2000prf.googl egroups.com...
          On Jun 7, 11:55 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
          use this method to check wheiter script already added or not...
          >>
          Page.ClientScri pt.IsClientScri ptBlockRegister ed();
          >>
          and to register use
          >>
          Page.ClientScri pt.RegisterClie ntScriptBlock() ;
          >>
          >Well, thanks. But not only does this not address the problem I've
          >described,
          >you're telling me to do exactly what the code I posted shows I was
          >already
          >doing.
          >>
          >--
          >Jonathan Wood
          >SoftCircuits Programminghttp ://www.softcircuit s.com
          >>
          >"Munna" <munna...@gmail .comwrote in message
          >>
          >news:085ec46 d-cee3-4b9b-9e8a-1c8fc7d3368b@j1 g2000prb.google groups.com...
          >On Jun 7, 11:08 am, "Jonathan Wood" <jw...@softcirc uits.comwrote:
          >>
          I'm trying to duplicate an HTML sample I have using my ASP.NET pages.
          >>
          The sample contains the following within the <headtag:
          >>
          <script type="text/javascript" src="flashobjec t.js"></script>
          <script type="text/javascript">
          // <![CDATA[
          var args = new Object();
          var query = location.search .substring(1);
          // Get query string
          var pairs = query.split( "," );
          // Break at comma
          for ( var i = 0; i < pairs.length; i++ )
          {
          var pos = pairs[i].indexOf('=');
          if( pos == -1 )
          {
          continue; // Look for "name=value "
          }
          var argname = pairs[i].substring( 0, pos ); // If not found, skip
          var value = pairs[i].substring( pos + 1 ); // Extract the name
          args[argname] = unescape( value ); // Extract the value
          }
          // ]]>
          </script>
          >>
          To do this the ASP.NET way, I added the following code to my Page_Load
          handler:
          >>
          if (!Page.ClientSc ript.IsClientSc riptBlockRegist ered("FlashObje ct"))
          Page.ClientScri pt.RegisterClie ntScriptInclude (typeof(Page),
          "FlashObjec t", "flashobject.js ");
          >>
          if (!Page.ClientSc ript.IsStartupS criptRegistered ("PrepVideo" ))
          Page.ClientScri pt.RegisterStar tupScript(typeo f(Page), "PrepVideo" ,
          "var args=new Object();" +
          "var query=location. search.substrin g(1);" +
          "var pairs=query.spl it(',');" +
          "for (var i=0;i < pairs.length;i+ +){" +
          "var pos=pairs[i].indexOf('=');" +
          "if (pos==-1) continue;" +
          "var argname=pairs[i].substring(0,po s);" +
          "var value=pairs[i].substring(pos + 1);" +
          "args[argname]=unescape(value );}", true);
          }
          >>
          I assume the second script is a start-up script since it is not a
          callable
          function. So this seems like it should work but it does not duplicate
          the
          functionality of the sample.
          >>
          Looking at the HTML produced, I see neither registered scripts are
          placed
          within the <headtag. So instead of calling
          RegisterClientS criptInclude
          and
          RegisterStartup Script, I instead forced these scripts into the <head>
          tag
          and they WORKED!!
          >>
          Unfortunately, I need to put this in a control that really should
          register
          the scripts in an organized way.
          >>
          Is there any way to register a script such that it is inserted within
          the
          <headtag? Or perhaps there's something else I'm missing?
          >>
          Thanks.
          >>
          Jonathan
          >
          Hi Jonathan
          >
          "RegisterStartu pScript" add scripts just before the end of "</body>"
          tag..
          and "RegisterClient ScriptBlock" add script inside the form as far as i
          seen so far..
          well since you need the script in the head block here is a work around
          i found and worked for me...
          >
          i added a literal control in size the head tag
          >
          <head id="Myhead" runat="server">
          <title>Untitl ed Page</title>
          <asp:Literal ID="ScriptSourc e" runat="server"> </asp:Literal>
          </head>
          >
          and in page load event i did this
          >
          ScriptSource.Te xt = "<script>window .alert('Worked okay');</script>";
          >
          surely you need to do some coding to adjust what you want to insert in
          head...
          >
          Best of luck
          >
          Munna


          www.shatkotha.com

          Comment

          Working...