javascript - Calling Code-Behind function from AJAX directly without page load -
i trying call code behind function directly. @ moment able call function pageload event of ajax.aspx.vb , pass response through variable on ajax.aspx <%= m_result %>
. works fine. however, not want go through pageload event, target function directly without having put data <%= m_result %>
. possible?
i using dotnetnuke functionality comes ascx controls. so, in ascx
control have 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 ajax.aspx.vb:
protected m_result string = "" protected sub page_load(byval sender object, byval e system.eventargs) handles me.load dim smoduleidreferrer string if not httpcontext.current.request.urlreferrer nothing strurl = httpcontext.current.request.urlreferrer.tostring dim spageindex integer if integer.tryparse(request("spageindex"), spageindex) gettestdata(spageindex) end if end if end sub <system.web.services.webmethod()> _ public shared function gettestdata(byval name integer) string m_result = "some test" return m_result end function
in ajax.aspx:
<%@ page language="vb" autoeventwireup="false" codebehind="ajax.aspx.vb" inherits="christoc.modules.top3all.ajax" %> <%= m_result %>
after adding <system.web.services.webmethod()>
@david says, try changing js use pagemethods, check answer, there can find need.
hope help
Comments
Post a Comment