我在一个aspx页面上有一个带有html控件的表单。当我点击提交时,它会通过表单将数据发布到另一个aspx页面。将数据保存到数据库后,如何使用表单返回上一页?现在,页面在aspx页面上停止,表单数据在保存后会传递。
表单(有更多的html控件,但我刚刚发布了基础知识) -
function ShowUploadFileDialog(CampaignId) {
var html = '';
var div = '#UploadFileDialog';
checkForId(div);
$(div).dialog({
width: '585px',
height: 'auto',
autoOpen: false,
show: "fade", //puff
hide: "fade", //clip
// zIndex: 3999,
position: "fixed top+80",
closeOnEscape: true,
modal: true,
close: function (event, ui) {
// Remove all items first
}
});
$.ajax({
type: 'POST',
url: 'CampaignsTest.aspx/LoadFiles',
data: JSON.stringify({
CampaignId: CampaignId
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
$("<img src='./Images/Logos/icon_pdf.gif'/>").prependTo("#UploadFileDialog_File");
var obj = $.parseJSON(msg.d);
var html = '';
html += ' <form id="CampaignUploadForm" action="UploadCampaignFile.aspx" method="post" enctype="multipart/form-data">';
html += ' <div>';
html += ' <div id="UploadFileDialog_Upload">';
html += ' <br /><br />';
html += ' <fieldset style="width: 535px; border: 1px solid #dcdcdc;">';
html += ' <legend style="font-size: 13px; font-weight: bold; margin: -22px 0 0 -11px;">Upload Document</legend><span style="color: Red; font-size: 10px; float: right; font-family: Arial;"> *Must be PDF File!</span>';
html += ' <table id="uploadTable">';
html += ' <br />';
html += ' <tr>';
html += ' <td align="right">';
html += ' <span Style="color: #666666; font-size: 11px; font-weight: bold; font-family: Arial">Upload File: </span>';
html += ' </td>';
html += ' <td>';
html += ' <input type="file" id="FileUpload1" name="FileUpload1" accept="application/pdf" class="pointer"/>';
html += ' </td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td align="right">';
html += ' <span style="color: #666666; font-size: 11px; font-weight: bold; font-family: Arial">Change File Name: </span>';
html += ' </td>';
html += ' <td>';
html += ' <input type="text" id="txtTitleName" name="txtTitleName" style="width: 300px;"/>';
html += ' </td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td align="right">';
html += ' <span style="color: #666666; font-size: 11px; font-weight: bold; font-family: Arial">Document Type: </span>';
html += ' </td>';
html += ' <td>';
html += ' <input type="text" id="txtFileType" name="txtFileType" style="width: 150px;"/>';
html += ' </td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td align="right">';
html += ' </td>';
html += ' <td class="style15">';
html += ' <input id="btnUpload" value="Submit" type="submit" name="btnUpload" class="pointer buton white regular" style="font-family: sans-serif; font-size: 10px;"/>   ';
html += ' </td>';
html += ' </tr>';
html += ' </table>';
html += ' </fieldset>';
html += ' </div>';
html += ' <div id="UploadFileDialog_File">';
html += '<table id="uploadPDFT" class="tablesorter">';
html += '<thead>';
html += '<tr style="color:white">';
html += '<th align="center"></th><th align="center">Document Name</th><th align="center">Document Type</th><th align="center">Date Uploaded</th><th></th>';
html += '</tr></thead>';
if (obj.Files.length > 0) {
for (var i = 0; i < obj.Files.length; i++) {
html += "<tr>";
html += '<td align="center"><img src="./Images/Logos/icon_pdf.gif"/></td><td align="center">' + obj.Files[i].Name + '</td><td align="center">' + obj.Files[i].Type + '</td><td align="center">' + obj.Files[i].DateCreated + '</td>';
html += '<td align="right"><div class="bootstrap"><div class="btn-group"><button class="btn btn-mini dropdown-toggle" data-toggle="dropdown">Options<span class="caret"></span></button><ul class="pull-right dropdown-menu pointer" style="font-size: 11px;">';
html += '<li class="bsbi"><a onclick="DownloadFile(' + obj.Files[i].Id + ')">Open</a></li>';
if (obj.RoleType == 3) {
if (obj.Files[i].StatusCode == 0)
html += '<li class="bsbi"><a onclick="DeleteFile(' + obj.Files[i].Id + ')">Remove</a></li>';
if (obj.Files[i].StatusCode == 1)
html += '<li class="bsbi"><a onclick="RestoreFile(' + obj.Files[i].Id + ')">Restore</a></li>';
}
else if (obj.RoleType == 1 && obj.Files[i].RoleType == 1) {
html += '<li class="bsbi"><a onclick="DeleteClientFile(' + obj.Files[i].Id + ')">Delete</a></li>';
}
html += '</ul></div></div></td>';
html += "</tr>";
}
}
else {
html += "<tr>";
html += '<td colspan="4" style="text-align:center;"> A media plan is not available yet. Please check back later. </td>';
html += "</tr>";
}
html += "</table>";
html += ' </div>';
html += ' <input id="hfCampaignID" type="hidden" name="hfCampaignID"/>';
html += ' <br /><br /><br />';
html += ' </div></form>';
$(div).html(html);
$(div).dialog("open");
$('#CampaignUploadForm').on('submit', function (e) { //use on if jQuery 1.7+
var data = $("#CampaignUploadForm :input").serializeArray();
console.log(data); //use the console for debugging, F12 in Chrome, not alerts
return;
});
$("#hfCampaignID").val(CampaignId);
}
});
}
使用保存方法的第二个Aspx页面
protected void Page_Load(object sender, EventArgs e)
{
string campaign_id = Request.Form["hfCampaignID"];
string FileType = Request.Form["txtFileType"];
string TitleName = Request.Form["txtTitleName"];
HttpPostedFile file = (HttpPostedFile)Request.Files["FileUpload1"];
byte[] buffer = new byte[file.ContentLength];
file.InputStream.Read(buffer, 0, file.ContentLength);
using (CmsInterface.Cms lCms = new CmsInterface.Cms())
{
int CampaignID = int.Parse(campaign_id);
Entities.File MyFiles = new Entities.File();
MyFiles.FileData = buffer;
MyFiles.Title = TitleName;
MyFiles.FileName = file.FileName;
MyFiles.FileSize = buffer.LongLength;
MyFiles.DateCreated = DateTime.Now;
MyFiles.FileType = FileType;
MyFiles.UploadedByUserId = CmwSession.UserId;
lCms.AddFileToCampaign(MyFiles, CampaignID);
}
}