• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 836
  • Last Modified:

Calling a method in code behind from javascript

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 vb.net code. Please let me know how I can do it.
<script type="text/javascript">
    function Print() {
        window.print();
        document.getElementById('tblDash').style.display = 'none';        
        window.print();        
    }
    </script>
0
TrialUser
Asked:
TrialUser
1 Solution
 
GaryCommented:
vb.net is server side
javascript is client side

you cannot call one from the other

Explain more what you are trying to achieve
0
 
TrialUserAuthor Commented:
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
0
 
GaryCommented:
Then in your javascript all you should need to do after calling the print dialog is
window.location = "http://www.mysite.com/myredirectedtopage.html"

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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CodeCruiserCommented:
You can also have a button in page and call its click method using javascript.
0
 
Roopesh ReddyCommented:
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now