Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All
I got a problem on following issue as mention below.

How to call a method (which is written in VB code) by a function in JavaScript:
AS a Simple Example:

VB code in Default.aspx.vb:

Public Sub testcall()
End Sub

Function in Default.aspx:

<script type="text/javascript">
function test(){
-----> What should i write here in order to call "testcall" !!?

Share this answer
Ehsan5675 12-Feb-12 0:38am    
Thanks for you answers. Please take a look at this code.....still didn't work:

<html xmlns="">
<head runat="server">

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
__doPostBack('Button1', '');

// ]]>
<form id="form1" runat="server">

<asp:Button ID="Button1" runat="server" Text="btn_server" />
<input id="Button2" type="button" value="btn_client" önclick="return Button2_onclick()" /></div>


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Martin Arapovic 12-Feb-12 4:45am    
Hi, I think that you didn't read article from my first link. There you have all you need...
Sorry but it must work, because I done this a hundred times I think... :)
First mistake is to use server side ID's ("Button1" from your example). Button1 on client have different name.
You should write this in your js code: function Button2_onclick() { __doPostBack('<% Button1.UniqueID %>', ''); }
or you should use some page protected variable and Page.ClientScript.GetPostBackEventReference method like the article from from my first link says...
Use this code to call testcall by java :
<% testcall %>

Hope this helps.
Share this answer
Ehsan5675 11-Feb-12 22:47pm    
It works, but when i run the project, "testcall" will be automatically called on startup by the function, but I didnt call the function! see the example below. before I click on button, "testcall" the function call the "testcall"

<input id="Button1" type="button" value="button" önclick="test();" />

<script type="text/javascript">
function test(){
<% testcall %>


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900