Q: combining Javascript and ASP-function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • haakern@gmail.com

    Q: combining Javascript and ASP-function?

    Hi,

    In an aspx page, I've got a TreeView and a detail form and a print
    button. When the user clicks on the print button, I'd like to collapse
    the TreeView and send the page to the printer.
    Using Javascript, the print is easy:
    <asp:ImageButto n ID="btnPrint" runat="server" AlternateText=" Print"
    ImageUrl="~/images/print.gif"
    OnClientClick=" javascript:wind ow.print();retu rn false;" ToolTip="Print
    page" />

    However, I'm not able to combine the window.print() function with the
    necessary method to collapse the TreeView (MyTreeView.Col lapseAll()).

    Anyone who's got any pointers on how to combine the Javascript print-
    function with the ASP.NET TreeView.Collap se method on a single button?

    Thanks!

    Regards,
    -Haakon-

  • Eliyahu Goldin

    #2
    Re: combining Javascript and ASP-function?

    The "return false;" part of the OnClientClick tells the event not to
    progress to the server where the collapsing part is handled. Change it to
    "return true"

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]




    <haakern@gmail. comwrote in message
    news:1176712294 .120585.13550@p 77g2000hsh.goog legroups.com...
    Hi,
    >
    In an aspx page, I've got a TreeView and a detail form and a print
    button. When the user clicks on the print button, I'd like to collapse
    the TreeView and send the page to the printer.
    Using Javascript, the print is easy:
    <asp:ImageButto n ID="btnPrint" runat="server" AlternateText=" Print"
    ImageUrl="~/images/print.gif"
    OnClientClick=" javascript:wind ow.print();retu rn false;" ToolTip="Print
    page" />
    >
    However, I'm not able to combine the window.print() function with the
    necessary method to collapse the TreeView (MyTreeView.Col lapseAll()).
    >
    Anyone who's got any pointers on how to combine the Javascript print-
    function with the ASP.NET TreeView.Collap se method on a single button?
    >
    Thanks!
    >
    Regards,
    -Haakon-
    >

    Comment

    • haakern@gmail.com

      #3
      Re: combining Javascript and ASP-function?

      Thanks for the reply. I think I was a bit unclear on what I wanted to
      achieve.
      I need to collapse my TreeView before I print the page. So going to
      the server and collapsing the tree after firing off the browser print
      function will not solve my problem.

      I tried:

      <script runat="server">
      void CollapseTree(Ob ject sender, EventArgs e)
      {
      TreeView1.Colla pseAll();
      }
      </script>

      and then:

      <asp:ImageButto n ID="ImageButton 1" runat="server"
      AlternateText=" Print" ImageUrl="~/images/print.gif"
      OnClientClick=" CollapseTree;ja vascript:window .print();return true;"
      ToolTip="Print page" />

      but that results in the error: 'CollapseTree' is undefined - which is
      strange, given that I have other ASP-functions that DO work on e.g.
      OnSelectedIndex Changed

      Regards,
      -Haakon-

      On Apr 16, 10:46 am, "Eliyahu Goldin"
      <REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
      The "return false;" part of the OnClientClick tells the event not to
      progress to the server where the collapsing part is handled. Change it to
      "return true"
      >
      --
      Eliyahu Goldin,
      Software Developer & Consultant
      Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
      >

      Comment

      • Eliyahu Goldin

        #4
        Re: combining Javascript and ASP-function?

        What you put in OnClientClick runs on client side whereas CollapseTree is a
        server side method.

        You don't need to use OnClientClick. Instead let CollapseTree do its job and
        communicate a request to print to the client side.

        This article may help you for the last part:
        How to Pass Messages and Actions between Server and Client


        --
        Eliyahu Goldin,
        Software Developer & Consultant
        Microsoft MVP [ASP.NET]




        <haakern@gmail. comwrote in message
        news:1176714097 .205417.104170@ l77g2000hsb.goo glegroups.com.. .
        Thanks for the reply. I think I was a bit unclear on what I wanted to
        achieve.
        I need to collapse my TreeView before I print the page. So going to
        the server and collapsing the tree after firing off the browser print
        function will not solve my problem.
        >
        I tried:
        >
        <script runat="server">
        void CollapseTree(Ob ject sender, EventArgs e)
        {
        TreeView1.Colla pseAll();
        }
        </script>
        >
        and then:
        >
        <asp:ImageButto n ID="ImageButton 1" runat="server"
        AlternateText=" Print" ImageUrl="~/images/print.gif"
        OnClientClick=" CollapseTree;ja vascript:window .print();return true;"
        ToolTip="Print page" />
        >
        but that results in the error: 'CollapseTree' is undefined - which is
        strange, given that I have other ASP-functions that DO work on e.g.
        OnSelectedIndex Changed
        >
        Regards,
        -Haakon-
        >
        On Apr 16, 10:46 am, "Eliyahu Goldin"
        <REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
        >The "return false;" part of the OnClientClick tells the event not to
        >progress to the server where the collapsing part is handled. Change it to
        >"return true"
        >>
        >--
        >Eliyahu Goldin,
        >Software Developer & Consultant
        >Microsoft MVP
        >[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
        >>
        >

        Comment

        Working...