0

I have question about use vb.net in javascript.

<script runat="server">
    Dim x As String
    Function Addx(ByVal txt As String) As String
        x = txt
        Return x
    End Function
</script>

I use function "Addx" in javascript like this.

<script language="javascript" type="text/javascript>
    var Getx = "<%=Addx('Hello World') %>";
    alert(Getx);
</script>

But it does not work and has an error.

Argument not specified for parameter 'txt' of 'Public Function Addx(txt As String) As String

What can I do?

4
  • I just answered this question stackoverflow.com/questions/17425617/… Commented Jul 2, 2013 at 13:57
  • 2
    I thought the string delimiter for VB.NET was " (double quote). Invert them (' for JavaScript and " for VB.NET) and it'll work. Commented Jul 2, 2013 at 13:58
  • 2
    You should use a webservice for example to achieve this Commented Jul 2, 2013 at 13:59
  • @Microtechie and Marijke: he doesn't pass any value from client to server, web service isn't needed here (unless he has to make it asynchronous because Addx is very time consuming). Commented Jul 2, 2013 at 14:00

1 Answer 1

4

VB doesn't allow single quotes for strings. JavaScript does. So, switch them around, and it should work.

<script language="javascript" type="text/javascript">
    var Getx = '<%=Addx("Hello World") %>';
    alert(Getx);
</script>

Edit: Also, make sure to close your quotes in your script tag attributes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.