Calling a method in code behind from javascript

Posted on 2012-09-12
Last Modified: 2012-09-13
HOw can I call a method that I have in code behind .

I have the following javascript in my page. at the end of the function I want to execute some code. Please let me know how I can do it.
<script type="text/javascript">
    function Print() {
        document.getElementById('tblDash').style.display = 'none';        
Question by:TrialUser
    LVL 58

    Expert Comment

    by:Gary is server side
    javascript is client side

    you cannot call one from the other

    Explain more what you are trying to achieve

    Author Comment

    MAy be something like trigger an event , like a linkbutton click or soemthing?
    And have the code behind the link button click.

    What I am trying to do is :
    1) I need a print a receipt when a transaction is complete . I load the html for the page on page_preload.
    2) then javascript is executed on form loader
    3) after receipt is printed, I wa nt to clear some session objects and redirect to anothe page

    Please help thanks
    LVL 58

    Accepted Solution

    Then in your javascript all you should need to do after calling the print dialog is
    window.location = ""

    and in that page clear the sessions and continue on.

    But I think your logic maybe amiss, surely there is no reason to not just clear the session once they land on the print page i.e. in your code behind clear those sessions since they are not needed any more once the print page has been sent. And the print page should open in a new tab so they retain the original url
    LVL 9

    Expert Comment

    LVL 83

    Expert Comment

    You can also have a button in page and call its click method using javascript.
    LVL 23

    Expert Comment

    by:Roopesh Reddy

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now