So, I know how to call a method onclick of a button using ajax, but I'd like to do the same when a user selects something new on a dropdownlist. I'll show code for what I've tried below:
<asp:UpdatePanel ID="pnlHelloWorld" runat="server">
<ContentTemplate>
<div style="height: auto; overflow: auto; max-height:750px; width:100%;">
<asp:DropDownList ID="mydropdownlist" runat="server" Enabled="true" OnChange="changeMyTable"></asp:DropDownList>
<asp:Table ID="mytable" runat="server"></asp:Table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
In the page's aspx.vb:
Private Sub changeMyTable()
'Add rows to table
end sub
The problem is that "changeMyTable" is undefined when i change the dropdownlist.
How can I do this?
You are using the
OnChangeevent to call the code behind method from javascript. To access the code behind method you need to convert that method to theWebMethod. For that below is something you can try (Just an example)Javascript code -
Code behind method -
Now you can call your javascript function
greetfrom wherever you want and it will trigger the code behind methodgreetUser. More on this is available here.