如何重定向到默认页面 [英] How do I redirect to default page

查看:122
本文介绍了如何重定向到默认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的表单保存按钮中有以下代码。它将保存作为发给客户的书籍列表的记录。现在保存后,我还准备了一个PDF文件,其中列出了用户详细信息和发布的文档列表。



Hello everybody,

I have the following code in save button of my form. It will save the record(s) which are list of books issued to a customer. Now after saving, I am also preparing a PDF file which list the user details and the list of documents issued.

protected void save_record(object sender, EventArgs e){
    if (Session["signoutkey"] != null) { //update existing record
        if (Session["member_id"] != null) {
            Int64 primary_key = Convert.ToInt64(Session["signoutkey"]);
            int member_id = Convert.ToInt32(Session["member_id"]);
            
            DateTime? out_date = null;
            if (txt_out_date.Text != "") {
                out_date = DateTime.Parse(txt_out_date.Text);
            }

            signout_issue_master_dal objDal = new signout_issue_master_dal();
            objDal.UpdateMaster(primary_key, member_id, out_date);

            CreateOrderForm(primary_key);
            Response.Redirect("~/Default.aspx");
        }
    }
}





正如您将注意到函数CreateOrderForm在一切都被调用后被调用保存。此功能使用iTextSharp创建PDF文件。这部分工作正常,下面是编码的部分





As you will notice the function CreateOrderForm is called after everything is saved. This function creates a PDF file using iTextSharp. This part is also working fine and below is the portion of the coding

private void CreateOrderForm(Int64 master_id) {
        //Get order information from database
        List<Signout_Issue_detail> lstDetails = new List<Signout_Issue_detail>();
        signout_issue_detail_dal objDetailDal = new signout_issue_detail_dal();

        lstDetails = objDetailDal.GetOrderList(master_id);

        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);              
        pdfDoc.Open();

        Paragraph pgf = new Paragraph(@"Sign Out Key - Order Form");
        pgf.Alignment = Element.ALIGN_CENTER;
        pdfDoc.Add(pgf);

        //Table for Header Information
        PdfPTable table = new PdfPTable(2);
        table.TotalWidth = 570f;

        //fix the absolute width of the table
        table.LockedWidth = true;

        //relative col widths in proportions - 1/3 and 2/3
        float[] widths = new float[] {4f, 12f};
        table.SetWidths(widths);
        table.HorizontalAlignment = 0;
        //leave a gap before and after the table
        table.SpacingBefore = 20f;
        table.SpacingAfter = 30f;

        //cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        PdfPCell headerCell = new PdfPCell();
        headerCell.Border = Rectangle.NO_BORDER;

        //Row 1
        headerCell.Phrase = new Phrase("Order ID: ");
        table.AddCell(headerCell);

        headerCell.Phrase = new Phrase(master_id.ToString());
        table.AddCell(headerCell);

        //Row 2
        headerCell.Phrase = new Phrase("Member Name: ");
        table.AddCell(headerCell);

        headerCell.Phrase = new Phrase(lstDetails[0].member_name);
        table.AddCell(headerCell);

        //Row 3
        headerCell.Phrase = new Phrase("Address: ");
        table.AddCell(headerCell);

        headerCell.Phrase = new Phrase(lstDetails[0].member_address);
        table.AddCell(headerCell);

        pdfDoc.Add(table);
        //End of Header table

        pdfDoc.Close(); 

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Order.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();





我的问题是系统下载PDF文件后,我想移动用户远离当前页面。我尝试了各种不同的建议,但没有任何工作。



有人可以建议我应该使用什么方法吗?



My problem is that after the system has downloaded the PDF file, I want to move the user away from the current page. I have tried various different suggestions available however nothing is working.

Could somebody please suggest what method I should use?

推荐答案

请参阅我之前接受的答案 - 如何在Response.TransmitFile之后调用Response.Redirect [ ^ ]。
Refer my previous accepted answer - how to call Response.Redirect after Response.TransmitFile[^].


这篇关于如何重定向到默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆