我试图解决这个问题已经好几天了。 我有一个页面是网站上的邮件收件箱。您可以通过Facebook上的列表向朋友发送消息。
它有一个js文件中的AJAX代码,2个ashx文件和aspx,aspx.cs文件。
当用户想要向朋友发送消息时,我正在使用facebox弹出窗口。 现在我更改了UI删除的facebox并添加了一个母版页,以便现在该页面就像网站上的任何其他页面一样。但是在messages.aspx页面上添加了一个母版页 单击发送消息后,HttpContext的值变为null。 当页面首次加载时,它们正常工作,显示朋友列表和以前的消息。这是当我触发一个js函数来保存输入的消息时,点击发送它就丢失了。
在message.aspx页面中的我使用3个隐藏字段:
<script>
function SavePostedMessage() {
var SenderAccountID = $("#hdnSenderID").val();
var ReceiverAccountID = $("#hdnReceiverID").val();
var Days = $("#hdnDays").val();
var body = GetmessageData();
if (body != null || body != "")
SaveMessageInDatabase(SenderAccountID, ReceiverAccountID, body, Days);
}
</script>
<asp:HiddenField ID="hdnSenderID" runat="server" />
<asp:HiddenField ID="hdnReceiverID" runat="server" />
<asp:HiddenField ID="hdnDays" runat="server" />
<a style="cursor: pointer;" onclick="SavePostedMessage()">
<div style="height: 25px; width: 85px; float: left; margin-top: 28px; padding-top: 5px; background: #01B2E5; text-align: center;" id="uploadifyContainer">
<span style="color: White; font-size: 12px;font-weight:bold; margin-left: 5px; border: 1px solid #D4D4D4;" id="Content_lblAddPhoto">Send</span>
</div>
</a>
</div>
在messages.aspx.cs中,我在page_load中输入了注册js函数的代码:
ScriptManager.RegisterStartupScript(
this,
typeof(string),
"Play",
"javascript:GetMessageConversation('" + Request.QueryString["AccountID"] + "','" + _userSession.CurrentUser.AccountID + "','7');", true);
在Ajax.js中我定义了
function GetMessageConversation(SenderAccountID, ReceiverAccountID, Days) {
$("#hdnSenderID").val(SenderAccountID);
$("#hdnReceiverID").val(ReceiverAccountID);
$("#hdnDays").val(Days);
$("#divPostComment").show();
setSelected("trUser" + ReceiverAccountID);
$.ajax({
type: "POST",
url: "/MessageFacebox/GetMessageConversation.ashx",
data: 'SenderAccountID=' + SenderAccountID + "&ReceiverAccountID=" + ReceiverAccountID + "&Days=" + Days,
success: function (data) {
$('#messageconversationdata').html(data);
Scrollbottom();
},
error: function (errordata) {
alert('Sorry some error occurred');
}
});
}
function SaveMessageInDatabase(SenderAccountID, ReceiverAccountID, Body, days) {
$.ajax({
type: "POST",
url: "/MessageFacebox/SaveMessage.ashx",
data: 'SenderID=' + SenderAccountID + "&ReceiverID=" + ReceiverAccountID + "&Body=" + Body,
success: function (data) {
GetMessageConversation(SenderAccountID, ReceiverAccountID, days);
},
error: function () {
alert('Sorry some error occurred');
}
});
}
在GetMessageConversation.ashx
中 context.Request.Form["SenderAccountID"]
和context.Request.Form["ReceiverAccountID"]
会返回存储的值
Account senderAccount = _accountRepository
.GetAccountByAccountID(Convert.ToInt32(context.Request.Form["SenderAccountID"]));
Account receiverAccount = _accountRepository
.GetAccountByAccountID(Convert.ToInt32(context.Request.Form["ReceiverAccountID"]));
但是在SaveMessage.ashx
中Account senderAccount = _accountRepository
.GetAccountByAccountID(Convert.ToInt32(context.Request.Form["SenderID"])) ;
Account receiverAccount = _accountRepository
.GetAccountByAccountID(Convert.ToInt32(context.Request.Form["ReceiverID"] ));
context.Request.Form["SenderID"]
和context.Request.Form["ReceiverID"]
具有空值。
首次访问页面时加载第一个。当用户输入消息并单击messages.aspx
中的发送按钮时,将调用save函数没有母版页,一切正常。一旦我将主页文件添加到messages.aspx,代码就会停止工作。
提前致谢。