register start up script hell

Discussion in 'ASP .Net' started by AmitKu, Dec 13, 2006.

  1. AmitKu

    AmitKu Guest

    I'm trying to use RegisterStartupScript.

    I am making a call to it in Page_Load...and nothing shows up. Well
    that not's entirely true. Half the pages I've put it on do work
    properly, but the other half just don't work at all. Nothing shows up
    at all.

    How can I debug this? What are possible causes?

    Thanks,
    Amit
     
    AmitKu, Dec 13, 2006
    #1
    1. Advertising

  2. AmitKu

    AmitKu Guest

    Just so you know...I deleted everything and tried this and it still
    failed....

    protected void Page_Load( object sender, EventArgs e )
    {
    string newscript = "<script>hello</script>";
    Page.ClientScript.RegisterStartupScript( this.GetType(),
    "randomScript", newscript );
    bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    "randomScript" );
    }

    and fDidItWork = false at the end of this.

    Why??

    --Amit
     
    AmitKu, Dec 13, 2006
    #2
    1. Advertising

  3. Hi,
    Just change following line of code:
    Incorrect One :string newscript = "<script>hello</script>";
    Correct One:string newscript = "<script>alert('Hello ASP.NET'); </script>";

    if it is still not working then let me know

    Thanks and regards,
    manish bafna


    "AmitKu" wrote:

    > Just so you know...I deleted everything and tried this and it still
    > failed....
    >
    > protected void Page_Load( object sender, EventArgs e )
    > {
    > string newscript = "<script>hello</script>";
    > Page.ClientScript.RegisterStartupScript( this.GetType(),
    > "randomScript", newscript );
    > bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    > "randomScript" );
    > }
    >
    > and fDidItWork = false at the end of this.
    >
    > Why??
    >
    > --Amit
    >
    >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 14, 2006
    #3
  4. Hi,
    you can try following code also:

    Page.ClientScript.RegisterStartupScript(this.GetType(), "randomScript",
    " alert('Hello ASP.NET'); ", true);

    In the previous example, you are specifying a Boolean value setting of True
    so that .NET places the script on the ASP.NET page with <script> tags
    automatically.

    Thanks and Regards,
    manish bafna





    "AmitKu" wrote:

    > Just so you know...I deleted everything and tried this and it still
    > failed....
    >
    > protected void Page_Load( object sender, EventArgs e )
    > {
    > string newscript = "<script>hello</script>";
    > Page.ClientScript.RegisterStartupScript( this.GetType(),
    > "randomScript", newscript );
    > bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    > "randomScript" );
    > }
    >
    > and fDidItWork = false at the end of this.
    >
    > Why??
    >
    > --Amit
    >
    >
     
    =?Utf-8?B?TWFuaXNoIEJhZm5h?=, Dec 14, 2006
    #4
  5. AmitKu

    AmitKu Guest

    Nope doesn't work at all...same result.

    I was originally using some real javascript, before even trying just
    the "hello" to see if anything would work. So it's not a matter of
    using real javascript.

    --Amit


    Manish Bafna wrote:
    > Hi,
    > Just change following line of code:
    > Incorrect One :string newscript = "<script>hello</script>";
    > Correct One:string newscript = "<script>alert('Hello ASP.NET'); </script>";
    >
    > if it is still not working then let me know
    >
    > Thanks and regards,
    > manish bafna
    >
    >
    > "AmitKu" wrote:
    >
    > > Just so you know...I deleted everything and tried this and it still
    > > failed....
    > >
    > > protected void Page_Load( object sender, EventArgs e )
    > > {
    > > string newscript = "<script>hello</script>";
    > > Page.ClientScript.RegisterStartupScript( this.GetType(),
    > > "randomScript", newscript );
    > > bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    > > "randomScript" );
    > > }
    > >
    > > and fDidItWork = false at the end of this.
    > >
    > > Why??
    > >
    > > --Amit
    > >
    > >
     
    AmitKu, Dec 14, 2006
    #5
  6. AmitKu

    bruce barker Guest

    when you register the script, you use the type object to create a
    namespace for register scripts. when you check if registered you do not
    pass the type so you are checking in a different namespace, so it
    responds no.

    when you register a startup script it is rendered just before the
    </form>. as long as there are no redirect, transfer, response.end or
    clear content calls it should render.

    -- bruce (sqlwork.com)



    AmitKu wrote:
    > Just so you know...I deleted everything and tried this and it still
    > failed....
    >
    > protected void Page_Load( object sender, EventArgs e )
    > {
    > string newscript = "<script>hello</script>";
    > Page.ClientScript.RegisterStartupScript( this.GetType(),
    > "randomScript", newscript );
    > bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    > "randomScript" );
    > }
    >
    > and fDidItWork = false at the end of this.
    >
    > Why??
    >
    > --Amit
    >
     
    bruce barker, Dec 14, 2006
    #6
  7. AmitKu

    AmitKu Guest

    Hi Bruce,

    You were right about IsStartupScript....but the thing just doesn't show
    up. I don't know what to tell you....no redirect, transfer,
    response.end or clear content calls are made.

    What could I be doing wrong?

    Thanks,
    Amit


    bruce barker wrote:
    > when you register the script, you use the type object to create a
    > namespace for register scripts. when you check if registered you do not
    > pass the type so you are checking in a different namespace, so it
    > responds no.
    >
    > when you register a startup script it is rendered just before the
    > </form>. as long as there are no redirect, transfer, response.end or
    > clear content calls it should render.
    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    > AmitKu wrote:
    > > Just so you know...I deleted everything and tried this and it still
    > > failed....
    > >
    > > protected void Page_Load( object sender, EventArgs e )
    > > {
    > > string newscript = "<script>hello</script>";
    > > Page.ClientScript.RegisterStartupScript( this.GetType(),
    > > "randomScript", newscript );
    > > bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    > > "randomScript" );
    > > }
    > >
    > > and fDidItWork = false at the end of this.
    > >
    > > Why??
    > >
    > > --Amit
    > >
     
    AmitKu, Dec 14, 2006
    #7
  8. AmitKu

    AmitKu Guest

    Anybody else? It just doesn't show up....any ideas?

    Thanks,
    Amit

    AmitKu wrote:
    > Hi Bruce,
    >
    > You were right about IsStartupScript....but the thing just doesn't show
    > up. I don't know what to tell you....no redirect, transfer,
    > response.end or clear content calls are made.
    >
    > What could I be doing wrong?
    >
    > Thanks,
    > Amit
    >
    >
    > bruce barker wrote:
    > > when you register the script, you use the type object to create a
    > > namespace for register scripts. when you check if registered you do not
    > > pass the type so you are checking in a different namespace, so it
    > > responds no.
    > >
    > > when you register a startup script it is rendered just before the
    > > </form>. as long as there are no redirect, transfer, response.end or
    > > clear content calls it should render.
    > >
    > > -- bruce (sqlwork.com)
    > >
    > >
    > >
    > > AmitKu wrote:
    > > > Just so you know...I deleted everything and tried this and it still
    > > > failed....
    > > >
    > > > protected void Page_Load( object sender, EventArgs e )
    > > > {
    > > > string newscript = "<script>hello</script>";
    > > > Page.ClientScript.RegisterStartupScript( this.GetType(),
    > > > "randomScript", newscript );
    > > > bool fDidItWork = Page.ClientScript.IsStartupScriptRegistered(
    > > > "randomScript" );
    > > > }
    > > >
    > > > and fDidItWork = false at the end of this.
    > > >
    > > > Why??
    > > >
    > > > --Amit
    > > >
     
    AmitKu, Dec 14, 2006
    #8
    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. Arjen
    Replies:
    2
    Views:
    8,145
    Arjen
    Aug 13, 2003
  2. Darren Clark

    Best way to Register Client Script objects?

    Darren Clark, Aug 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    460
    Scott Allen
    Aug 2, 2004
  3. Hardy Wang

    Register client script question

    Hardy Wang, Oct 26, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,647
    Kevin Spencer
    Oct 26, 2004
  4. Henri
    Replies:
    2
    Views:
    4,127
    Henri
    Nov 7, 2004
  5. Roedy Green
    Replies:
    18
    Views:
    857
    Jeff Higgins
    Mar 26, 2008
Loading...

Share This Page