Click here to Skip to main content
15,922,533 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:

VB
Public Sub testcall()
        MsgBox("Done!")
End Sub




Function in Default.aspx:

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

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

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

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

// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

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



Server-Side:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Done")
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 :
Java
<% testcall %>


Hope this helps.
 
Share this answer
 
v2
Comments
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"

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

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

</div>

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