0

I'm trying to call the vb method by clicking on the div but i get that the method is not defined.

My Code:

<div id="Div1" class="btn btn-primary pull-right" runat="server" onclick="prueba2()" >
</div>

<script type="text/VB" runat="server">  
    Sub prueba2()
      MsgBox("seee")
    End Sub
</script>

Debug: Uncaught ReferenceError: prueba2 is not defined

Thanks in advance!

0

2 Answers 2

3

In this case, the onclick is for javascript:

<div id="Div1" class="btn btn-primary pull-right" runat="server" onclick="prueba2()" ></div>

<script type="text/javascript">
    function prueba2() {
        //do something
    }
</script>

Note, for ASP.NET controls, this is not the same. They will have OnClick for the code behind function and OnClientClick for the client-side javascript function:

<asp:Button ID="_someButton" OnClick="VBFunction" Text="Some Text" OnClientClick="prueba2()" runat="server" />
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, i replaced the div for asp button but i still get "Uncaught ReferenceError: msg2 is not defined "
@Fakedo0r if you are changing your code, you need to update your question. My example wasn't to say that you should replace your div with a button, it was to show that OnClick for an ASP control is different than the onclick of your div.
0

You'll have to change your onclick to a javascript that will submit the form using a button.

__doPostBack('btnTemp', '');

Where btnTemp is a button.

You can find a great example here: Adding OnClick event to ASP.NET control

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.