-1
在我的asp.net應用程序中我有一個按鈕,點擊時調用一個javascript函數。該函數使用pagemethods在後面的VB代碼中調用服務器端函數。這工作正常,並在函數結束時我返回一個字符串。當成功函數碰到客戶端時 - 返回值始終爲空。有人看到這個問題嗎?下面列出了一些代碼,以瞭解它是如何工作的。謝謝。Pagemethods的成功函數 - 返回值總是爲空
按鈕
<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。再次感謝。