Solved

Javascript do postback and run vbnet sub

Posted on 2014-01-20
1
1,088 Views
Last Modified: 2014-01-21
Is there a way to run a vbnet sub script via javascript?

Thanks,

WCGee
0
Comment
Question by:williecg
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39795922
You can use PageMethods :
http://www.dotnetcurry.com/showarticle.aspx?ID=109
http://msdn.microsoft.com/en-us/library/system.web.ui.page_methods(v=vs.110).aspx

Add this in your page :
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/>

Open in new window


Public Shared Function FunctionName(ByVal parame As String) As String
' DO SOMETHING
End Function

Open in new window


Javascript, client side :
function RunServerSideFunction(fieldID, target) {    
     var value = document.getElementById(fieldID).value;
     PageMethods.FunctionName(value, Success, Failed, target);
}
 
function Success(result, fieldID) {    
    document.getElementById(fieldID).value = result;
}
 
function Failed(error, fieldID) {
     alert(error);
}

Open in new window

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

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