生成pdf后清除所有字段 [英] Clear all fields after the pdf is generated

查看:116
本文介绍了生成pdf后清除所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Webform,它有一些文本框和下拉列表。

I have a Webform which have some textboxes and dropdowns .

点击保存按钮后,数据将保存在数据库中,并使用该数据生成pdf。

After clicking on Save button the data is saved in database and the pdf is generated using that data .

生成pdf后,pdf文件在浏览器中打开。

After the generation of pdf , the pdf file is opened in browser .

我在调用方法清除所有字段后,使用方法生成了pdf文件。

I've generated pdf file using a method then after i am calling a method to clear all fields .

生成pdf后,用户可以按下后退按钮并返回上一页,由于这个原因,我希望清除所有字段,但不能正常工作。我该如何解决这个问题?

After the pdf is generated , the user could press back button and can go back to previous page , Due to this reason I want all fields to be cleared but its not working . How can I resolve this ?

这是我的代码:

保存按钮代码

 protected void btn_submit_Click(object sender, EventArgs e)
    {
        if (IsValidQuotation())
        {
            string newQuotNum = rental_quotations.GetNewQuotNumber();
            double max_load = (Convert.ToDouble(generator_category.GetGeneratorDesc(ddl_gene_desc.SelectedValue)) * 0.8) * ((double)80 / (double)100);
            double min_load = (Convert.ToDouble(generator_category.GetGeneratorDesc(ddl_gene_desc.SelectedValue)) * 0.8) * ((double)50 / (double)100);
            rental_quotations.AddNewQuotation(newQuotNum, Session["empcd"].ToString(), ddl_gene_type.SelectedValue.ToString(), ddl_gene_desc.SelectedValue, ddl_canopy.SelectedValue, txt_company.Text, txt_address.Text, txt_contactperson.Text, txt_designation.Text, txt_contact1.Text, txt_contact2.Text, txt_rentalamount.Text, ddl_terms.SelectedValue, txt_hours.Text, txt_variable.Text, txt_remarks.Text, min_load.ToString(), max_load.ToString(),ddl_sign1.SelectedValue,ddl_sign2.SelectedValue);
            GetPDF(newQuotNum);
        }
    }

这是生成PDF的方法:

This is the method where PDF is generated :

public void GetPDF(string quote_num)
    {
        string url = FilesPath.Path_SaveFile + Session["empcd"].ToString() +"-Quotation.pdf";
        Document disclaimer = new Document(PageSize.A4, 2, 2, 10, 10);
        PdfWriter writer = PdfWriter.GetInstance(disclaimer, new FileStream(url, FileMode.Create));
        writer.PageEvent = new myPDFpgHandler(quote_num);
        disclaimer.SetMargins(10, 10, 70,80);
        disclaimer.Open();
        GenerateQuotPDF getpdf = new GenerateQuotPDF();
        disclaimer = getpdf.GetPDFparams(disclaimer,quote_num, Session["empcd"].ToString(),txt_contactperson.Text,txt_contact1.Text,txt_company.Text,txt_address.Text,ddl_gene_desc.SelectedItem.ToString(),ddl_canopy.SelectedItem.ToString(),ddl_gene_type.SelectedItem.ToString(),txt_rentalamount.Text,txt_hours.Text,txt_variable.Text,ddl_terms.SelectedItem.ToString(),txt_remarks.Text,txt_technical.Text,ddl_sign1.SelectedValue,ddl_sign2.SelectedValue,txt_designation.Text,DateTime.Now);
        disclaimer.Close();
        ClearAllFields(); // this is not working in back Case 
        System.IO.FileInfo file = new System.IO.FileInfo(url);
        if (file.Exists)
        {
            WebClient client = new WebClient();
            Byte[] buffer = client.DownloadData(url);
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", buffer.Length.ToString());
            Response.BinaryWrite(buffer);
        }
    }

在浏览器中打开pdf后,用户可以返回该页面并且所有字段都不会被清除

After the pdf is opened in the browser , the user could go back to that page and all fields are not cleared

我该如何处理这个?

感谢您的帮助

推荐答案

您可以通过使用页面的enableviewstate ='false'来实现

you can achieve by either using the enableviewstate='false' of the page

OR

您可以在执行'GetPDF(newQuotNum)'函数调用后重置所有控制值。像这样

you can reset all the control value after the execution of 'GetPDF(newQuotNum)' function call. Like this

protected void btn_submit_Click(object sender, EventArgs e)
{
    if (IsValidQuotation())
    {
        string newQuotNum = rental_quotations.GetNewQuotNumber();
        double max_load = (Convert.ToDouble(generator_category.GetGeneratorDesc(ddl_gene_desc.SelectedValue)) * 0.8) * ((double)80 / (double)100);
        double min_load = (Convert.ToDouble(generator_category.GetGeneratorDesc(ddl_gene_desc.SelectedValue)) * 0.8) * ((double)50 / (double)100);
        rental_quotations.AddNewQuotation(newQuotNum, Session["empcd"].ToString(), ddl_gene_type.SelectedValue.ToString(), ddl_gene_desc.SelectedValue, ddl_canopy.SelectedValue, txt_company.Text, txt_address.Text, txt_contactperson.Text, txt_designation.Text, txt_contact1.Text, txt_contact2.Text, txt_rentalamount.Text, ddl_terms.SelectedValue, txt_hours.Text, txt_variable.Text, txt_remarks.Text, min_load.ToString(), max_load.ToString(),ddl_sign1.SelectedValue,ddl_sign2.SelectedValue);
        GetPDF(newQuotNum);
        ClearForm();
    }
}

private void ClearForm()
{
    foreach( var control in this.Controls )
    {
         var textbox = control as TextBox;
         if (textbox != null)
              textbox.Text = string.Empty;

         var dropDownList = control as DropDownList;
         if (dropDownList != null)
              dropDownList.SelectedIndex = 0;

         }
 }

希望这可以解决您的问题。

hope this will resolve your problem.

这篇关于生成pdf后清除所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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