Solved

Javascript do postback and run vbnet sub

Posted on 2014-01-20
1
1,051 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
This article will show, step by step, how to integrate R code into a R Sweave document
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

19 Experts available now in Live!

Get 1:1 Help Now