-1

在我的 asp.net 应用程序中,我有一个按钮,单击该按钮会调用 javascript 函数。这个函数使用pagemethods在后面的VB代码中调用一个服务器端函数。这可以正常工作,并且在函数结束时我返回一个字符串。当成功函数在客户端命中时 - 返回值始终为空。有人看到这个问题吗?下面列出了一些代码,看看它是如何工作的。谢谢你。

按钮

<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);
}

服务器端的保存功能(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

从这里开始,当成功函数命中时,我使用警报查看返回字符串的值,我总是得到 null - 成功 JS 函数

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

另外,我在服务器端导入以下内容

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

我还在客户端包含了以下脚本管理器

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

感谢您的帮助。我过去经常使用页面方法,但我似乎无法弄清楚为什么在这种情况下我总是重新输入 null。再次感谢。

4

1 回答 1

0

问题已解决,问题出在服务器端函数中,无法使用 httpcontext.current.response.write - 这导致返回失败

于 2012-12-12T15:01:12.500 回答