Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 表单数据传递到aspx页面并保存后,如何在不回发的情况下返回到上一页_C#_Javascript_Jquery_Html - Fatal编程技术网

C# 表单数据传递到aspx页面并保存后,如何在不回发的情况下返回到上一页

C# 表单数据传递到aspx页面并保存后,如何在不回发的情况下返回到上一页,c#,javascript,jquery,html,C#,Javascript,Jquery,Html,我在一个aspx页面上有一个带有JavaScript html控件的表单。当我单击submit时,它会通过表单将数据发布到另一个aspx页面。数据保存到数据库后,如何使用表单返回上一页?现在,页面停止在保存表单数据后传递表单数据的aspx页面上 表单(有更多的html控件,但我只是发布了一些基本内容)- “表单数据传递到aspx页面并保存后”不是回发吗?我想你要找的是ajax。是的,我需要的是页面不刷新并返回到上一点,然后你只需要使用ajax将数据发布到服务器。数据已经成功发布,但我只需要重定向

我在一个aspx页面上有一个带有JavaScript html控件的表单。当我单击submit时,它会通过表单将数据发布到另一个aspx页面。数据保存到数据库后,如何使用表单返回上一页?现在,页面停止在保存表单数据后传递表单数据的aspx页面上

表单(有更多的html控件,但我只是发布了一些基本内容)-


“表单数据传递到aspx页面并保存后”不是回发吗?我想你要找的是ajax。是的,我需要的是页面不刷新并返回到上一点,然后你只需要使用ajax将数据发布到服务器。数据已经成功发布,但我只需要重定向到表单来自的前一个aspx页面,而不刷新页面。对,这正是ajax所做的。如果您不停止按现在的方式发布,而是使用ajax,那么它不会停止刷新页面。
    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;"/> &nbsp&nbsp';
                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);
            }
        });
    }
    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);
        }
    }