Pergunta

in my asp.net application I have a button that when clicked calls a javascript function. This function uses pagemethods to call a server side function in the VB code behind. This works correctly and at the end of the function I am returning a string. When the success function hits on the client side - the return value is always null. Is anyone seeing the issue? Listed below are pieces of the code to see how this is working. Thank you.

Button

<asp:button id="btnSaveSoln" onclientclick="refreshParentTree()" runat="server" Text="Save" Cssclass="smalltextbutton"></asp:button>

refreshParentTree Javascript

function refreshParentTree() {

var chkUpdate = document.getElementById('chkUpdatePlanner');
var chkValue;
if (chkUpdate != null) {
    if (document.getElementById('chkUpdatePlanner').checked = true) {
              chkValue = 1;
    }
    else {
              chkValue = 0;
    }
}
else {
    chkValue = 0;
}

var txtClient = document.getElementById('txtClientID');
var txtClientValue;
if (txtClient != null) {
    txtClientValue = document.getElementById('txtClientID').value;
}
else {
    txtClientValue = '';
}


PageMethods.save(document.getElementById('hdnProjectCreator').value,     document.getElementById('txtTitle').value, document.getElementById('txtDescription').value, document.getElementById('hdnProjectManager').value, document.getElementById('txtSchedStart').value, document.getElementById('hdnApprover').value, document.getElementById('dropdownProjectType').value, document.getElementById('drpdownProjectPriority').value, txtClientValue, 0, document.getElementById('DropDownPhaseList').value, chkValue, document.getElementById('DropDownWorkWeekLengthList').value, document.getElementById('hdnTemplateID').value, saveSuccess, saveFailure);
}

save function on server side (VB)

 <System.Web.Services.WebMethod()> _
    Public Shared Function save(ByVal hdnProjCreator As String, ByVal titleTxt As String, ByVal desc As String, ByVal hdnProjManager As String, ByVal SchedStart As String, ByVal ApproverTxt As String, ByVal ddProjectType As String, ByVal ddProjectPriority As String, ByVal ClientIDtxt As String, ByVal ddEquipmentList As String, ByVal ddPhaseList As String, ByVal UpdatePlanner As String, ByVal ddWorkWeekLengthList As String, ByVal TemplateID As String)
    ***** SQL Computing here, removed for stack overflow - ddWorkWeekVisable, lnResult, parentID and taskgrpPCat are all strings *****  

        Dim returnString As String = ddWorkWeekVisable & ":" & lnResult & ":10:" & parentID & ":" & taskgrpPCat
        Return returnString


    End Function

From here when the success function hits, I have used an alert to see the value of the return string, I am always getting null - success JS function

function saveSuccess(response) {
alert('save success hit - response: ' + response)
}

Also, I am importing the following on the server side

Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Web.Services
Imports System.Web.Services.WebMethodAttribute
Imports System.Web.SessionState.SessionStateMode
Imports System.Web.UI.WebControls
Imports System.Web
Imports System.Data

I have also included the below script manager on the client side

 <asp:ScriptManager ID="ScriptManager1" runat="server"   
      EnablePageMethods="True">
</asp:ScriptManager>

Thank you for your help. I have used pagemethods often in the past, but I can't seem to figure out why I'm always reutrning null in this case. Thanks again.

Foi útil?

Solução

Issue Resolved, issue was in the server side function, can not use httpcontext.current.response.write - this was throwing off the return

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top