I am trying to call a code behind function directly. At the moment I am able to call the function from the PageLoad event of my ajax.aspx.vb and I pass the response through my variable which is on the ajax.aspx <%= m_result %>
. This works fine. However, I do not want to go through the PageLoad event, but to target the function directly without having to put data into the <%= m_result %>
. Is it possible?
I am using DotNetNuke where all the functionality are comes from ascx controls.
So, in my ascx
control I have the ajax as:
<script type = "text/javascript">
function JSFunction() {
var xx = 1;
$.ajax({
type: "POST",
url: "/top3/DesktopModules/top3all/ajax.aspx/GetTestData",
data: { 'sPageIndex': xx},
}).done(function (response) {
OnSuccessTest(response);
});
}
function OnSuccessTest(response) {
document.getElementById("<%= lblTest.ClientID%>").innerHTML = response;
}
</script>
In my ajax.aspx.vb:
Protected m_result As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sModuleIDReferrer As String
If Not HttpContext.Current.Request.UrlReferrer Is Nothing Then
strUrl = HttpContext.Current.Request.UrlReferrer.ToString
Dim sPageIndex As Integer
If Integer.TryParse(Request("sPageIndex"), sPageIndex) Then
GetTestData(sPageIndex)
End If
End If
End Sub
<System.Web.Services.WebMethod()> _
Public Shared Function GetTestData(ByVal name As Integer) As String
m_result = "some test"
Return m_result
End Function
In my ajax.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ajax.aspx.vb" Inherits="Christoc.Modules.top3all.ajax" %>
<%= m_result %>