在我的asp.net应用程序中,我有一个按钮,当点击时调用一个javascript函数。此函数使用页面方法在后面的VB代码中调用服务器端函数。这工作正常,在函数结束时我返回一个字符串。当成功函数在客户端命中时 - 返回值始终为null。有人看到这个问题吗?下面列出了一些代码,以了解它是如何工作的。谢谢。
按钮
<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。再次感谢。
答案 0 :(得分:0)