RegisterClientScriptBlock - does not work

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

    #1

    RegisterClientScriptBlock - does not work

    Hi,

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    System.Text.Str ingBuilder strBuilder = new System.Text.Str ingBuilder();
    strBuilder.Appe nd ("<script language=JavaSc ript> ");
    strBuilder.Appe nd ("<!--");
    strBuilder.Appe nd ("var intWidth = window.screen.a vailWidth - 40;");
    strBuilder.Appe nd ("var intHeight = window.screen.a vailHeight - 60;");
    strBuilder.Appe nd ("var strHrf;");
    //DoD function
    strBuilder.Appe nd ("function DoDClick(Site) {");
    strBuilder.Appe nd ("window.event. returnValue = false;");
    strBuilder.Appe nd ("if (Site == 'SHIP'){");
    strBuilder.Appe nd ("strHrf = 'Ship/ShDoD.htm';}");
    strBuilder.Appe nd ("else{");
    strBuilder.Appe nd ("strHrf = 'DoD.aspx';}");
    strBuilder.Appe nd ("newWindow(Sit e, 'DoD', intHeight, intWidth, true,
    false, true, false);}");
    strBuilder.Appe nd ("function SiteClick(Site) {");
    strBuilder.Appe nd ("window.event. returnValue = false;");
    strBuilder.Appe nd ("if (Site == 'SHIP'){");
    strBuilder.Appe nd ("strHrf = 'Ship/ShDefaultShip.h tm';}");
    strBuilder.Appe nd ("else{");
    strBuilder.Appe nd ("strHrf = 'DefaultShore.h tm';}");
    strBuilder.Appe nd ("newWindow(str Hrf, 'RADWeb', intHeight, intWidth,
    true, false, true, false);}");
    strBuilder.Appe nd ("-->");
    strBuilder.Appe nd ("</script>");
    string js = strBuilder.ToSt ring();
    if (!IsClientScrip tBlockRegistere d("DoDClick") )
    {
    RegisterClientS criptBlock("DoD Click", js);
    }

    if (!IsClientScrip tBlockRegistere d("SiteClick" ))
    {
    RegisterClientS criptBlock("Sit eClick", js);
    }
    }

    ------------------------------

    Everything looks good. No error.
    Also get
    IsClientScriptB lockRegistered = true

    No Javascript is genrated when I view source code.

    Not sure what I am doing wrong.

    Thanks,

    - Reena


  • joel

    #2
    RegisterClientS criptBlock - does not work

    [color=blue]
    >-----Original Message-----
    >Hi,
    >
    >private void Page_Load(objec t sender, System.EventArg s e)
    >{
    > System.Text.Str ingBuilder strBuilder = new[/color]
    System.Text.Str ingBuilder();[color=blue]
    > strBuilder.Appe nd ("<script language=JavaSc ript> ");
    > strBuilder.Appe nd ("<!--");
    > strBuilder.Appe nd ("var intWidth =[/color]
    window.screen.a vailWidth - 40;");[color=blue]
    > strBuilder.Appe nd ("var intHeight =[/color]
    window.screen.a vailHeight - 60;");[color=blue]
    > strBuilder.Appe nd ("var strHrf;");
    > //DoD function
    > strBuilder.Appe nd ("function DoDClick(Site) {");
    > strBuilder.Appe nd ("window.event. returnValue =[/color]
    false;");[color=blue]
    > strBuilder.Appe nd ("if (Site == 'SHIP'){");
    > strBuilder.Appe nd ("strHrf = 'Ship/ShDoD.htm';}");
    > strBuilder.Appe nd ("else{");
    > strBuilder.Appe nd ("strHrf = 'DoD.aspx';}");
    > strBuilder.Appe nd ("newWindow(Sit e, 'DoD', intHeight,[/color]
    intWidth, true,[color=blue]
    >false, true, false);}");
    > strBuilder.Appe nd ("function SiteClick(Site) {");
    > strBuilder.Appe nd ("window.event. returnValue =[/color]
    false;");[color=blue]
    > strBuilder.Appe nd ("if (Site == 'SHIP'){");
    > strBuilder.Appe nd ("strHrf[/color]
    = 'Ship/ShDefaultShip.h tm';}");[color=blue]
    > strBuilder.Appe nd ("else{");
    > strBuilder.Appe nd ("strHrf = 'DefaultShore.h tm';}");
    > strBuilder.Appe nd ("newWindow(str Hrf, 'RADWeb',[/color]
    intHeight, intWidth,[color=blue]
    >true, false, true, false);}");
    > strBuilder.Appe nd ("-->");
    > strBuilder.Appe nd ("</script>");
    > string js = strBuilder.ToSt ring();
    > if (!IsClientScrip tBlockRegistere d("DoDClick") )
    > {
    > RegisterClientS criptBlock("DoD Click",[/color]
    js);[color=blue]
    > }
    >
    > if (!IsClientScrip tBlockRegistere d("SiteClick" ))
    > {
    > RegisterClientS criptBlock("Sit eClick", js);
    > }
    > }
    >
    >------------------------------
    >
    >Everything looks good. No error.
    >Also get
    > IsClientScriptB lockRegistered = true
    >
    >No Javascript is genrated when I view source code.
    >
    >Not sure what I am doing wrong.
    >
    >Thanks,
    >
    >- Reena
    >
    >
    >.
    >Reena - I created a new project, cut & paster your code[/color]
    and it ran without error. Did a 'View Source' and it was
    there. Did you try a new project to see if maybe there's
    something else wrong with your existing project?

    Comment

    • Reena

      #3
      Re: RegisterClientS criptBlock - does not work

      Thanks Joel. Tried with new project. Works fine. Can see javascript in view
      source.

      Error while accessing javascript...

      Microsoft JScript runtime error: Object expected

      ---------------- HTML Code ----------------
      <a id="hrfShip" onclick="SiteCl ick('SHIP')" href="-">Ship:</a>
      <a href="-" onclick="SiteCl ick('SHORE')">S hore:</a>
      <a href="-" onclick="DoDCli ck('<% =Session["RADSite"] %>')">DoD
      Disclamier</a>



      _______________ ______

      Thanks,

      - Reena

      "joel" <joel@brandes.n ospam.com> wrote in message
      news:425d01c376 56$7f296470$a10 1280a@phx.gbl.. .[color=blue]
      >[color=green]
      > >-----Original Message-----
      > >Hi,
      > >
      > >private void Page_Load(objec t sender, System.EventArg s e)
      > >{
      > > System.Text.Str ingBuilder strBuilder = new[/color]
      > System.Text.Str ingBuilder();[color=green]
      > > strBuilder.Appe nd ("<script language=JavaSc ript> ");
      > > strBuilder.Appe nd ("<!--");
      > > strBuilder.Appe nd ("var intWidth =[/color]
      > window.screen.a vailWidth - 40;");[color=green]
      > > strBuilder.Appe nd ("var intHeight =[/color]
      > window.screen.a vailHeight - 60;");[color=green]
      > > strBuilder.Appe nd ("var strHrf;");
      > > //DoD function
      > > strBuilder.Appe nd ("function DoDClick(Site) {");
      > > strBuilder.Appe nd ("window.event. returnValue =[/color]
      > false;");[color=green]
      > > strBuilder.Appe nd ("if (Site == 'SHIP'){");
      > > strBuilder.Appe nd ("strHrf = 'Ship/ShDoD.htm';}");
      > > strBuilder.Appe nd ("else{");
      > > strBuilder.Appe nd ("strHrf = 'DoD.aspx';}");
      > > strBuilder.Appe nd ("newWindow(Sit e, 'DoD', intHeight,[/color]
      > intWidth, true,[color=green]
      > >false, true, false);}");
      > > strBuilder.Appe nd ("function SiteClick(Site) {");
      > > strBuilder.Appe nd ("window.event. returnValue =[/color]
      > false;");[color=green]
      > > strBuilder.Appe nd ("if (Site == 'SHIP'){");
      > > strBuilder.Appe nd ("strHrf[/color]
      > = 'Ship/ShDefaultShip.h tm';}");[color=green]
      > > strBuilder.Appe nd ("else{");
      > > strBuilder.Appe nd ("strHrf = 'DefaultShore.h tm';}");
      > > strBuilder.Appe nd ("newWindow(str Hrf, 'RADWeb',[/color]
      > intHeight, intWidth,[color=green]
      > >true, false, true, false);}");
      > > strBuilder.Appe nd ("-->");
      > > strBuilder.Appe nd ("</script>");
      > > string js = strBuilder.ToSt ring();
      > > if (!IsClientScrip tBlockRegistere d("DoDClick") )
      > > {
      > > RegisterClientS criptBlock("DoD Click",[/color]
      > js);[color=green]
      > > }
      > >
      > > if (!IsClientScrip tBlockRegistere d("SiteClick" ))
      > > {
      > > RegisterClientS criptBlock("Sit eClick", js);
      > > }
      > > }
      > >
      > >------------------------------
      > >
      > >Everything looks good. No error.
      > >Also get
      > > IsClientScriptB lockRegistered = true
      > >
      > >No Javascript is genrated when I view source code.
      > >
      > >Not sure what I am doing wrong.
      > >
      > >Thanks,
      > >
      > >- Reena
      > >
      > >
      > >.
      > >Reena - I created a new project, cut & paster your code[/color]
      > and it ran without error. Did a 'View Source' and it was
      > there. Did you try a new project to see if maybe there's
      > something else wrong with your existing project?[/color]


      Comment

      • Hans Kesting

        #4
        Re: RegisterClientS criptBlock - does not work


        "Reena" <palejar@navsea .navy.mil> wrote in message
        news:%233MCLNld DHA.748@TK2MSFT NGP10.phx.gbl.. .[color=blue]
        > Hi,
        >
        > private void Page_Load(objec t sender, System.EventArg s e)
        > {
        > System.Text.Str ingBuilder strBuilder = new System.Text.Str ingBuilder();
        > strBuilder.Appe nd ("<script language=JavaSc ript> ");
        > strBuilder.Appe nd ("<!--");
        > strBuilder.Appe nd ("var intWidth = window.screen.a vailWidth - 40;");
        > strBuilder.Appe nd ("var intHeight = window.screen.a vailHeight - 60;");
        > strBuilder.Appe nd ("var strHrf;");[/color]
        <etc.>

        Reena,

        just a tip:

        you could write this as
        string js = @"<script language=JavaSc ript>
        <!--
        var intWidth = window.screen.a vailWidth - 40;
        var intHeight = window.screen.a vailHeight - 60;
        var strHrf;
        <etc>";

        this is, as a single multi-line string. For a fixed text it is easier to
        read.

        Hans Kesting




        Comment

        Working...