1

i have a big problem and i need your help. i'm trying send to url parameters to generate the pdf file with the library winnovative. when trying the first time I have no problems and generates pdf but if I want to get the pdf again this gives me error because the parameters in url they are sent and fail to request and falls when so finally assign to generate the pdf file. I have attached the code for review:

 public override void Pagina_PrimeraCarga(object sender, EventArgs e)
    {

        string datosRequest = Request.QueryString["DATOS"];
        char delimitadores = ';';
        string[] datos = datosRequest.Split(delimitadores);

        imgBanco.Attributes.Add("ImageUrl", "~/App_Themes/Imagenes/Logo.gif");
        System.DateTime fecha = new System.DateTime(2014, 12, 17);
        lblDia.Text = Convert.ToString(fecha.Day);
        lblMes.Text = Convert.ToString(fecha.Month);
        lblAno.Text = Convert.ToString(fecha.Year);

        string rutEmpresa = datos[3];
        int rut = Convert.ToInt32(rutEmpresa);
        string rutRes = rut.ToString("N0", CultureInfo.InvariantCulture).Replace(",", ".");
        rutRes = rutRes + "-" + datos[4];

        lblOficina.Text = "OFICINA: " + datos[0];
        lblNombreTitular.Text = "NOMBRE TITULAR: " + datos[1];
        lblRut.Text = "R.U.T.: " + rutRes;
        lblDireccion.Text = "DIRECCION: " + datos[2];
        lblFono.Text = "FONO: " + datos[5];
    }

P.D: my apologies for my bad English but my native language is Spanish P.D.2: Thanks to everyone who could help me in this case

2 Answers2

0

I think that your problem is that after postBack your query string will be empty. Try this

add hiddenfield

<asp:HiddenField runat="server" ID="hidden1" />

then in your pageLoad

 if (!IsPostBack)
 {
   string datosRequest = Request.QueryString["DATOS"];
    if(datosRequest  != null)
    {
      //do something
      hidden1.Value = datosRequest ;
    }
 }
 else
 {
   datosRequest = hidden1.Value;
 }
faby
  • 7,394
  • 3
  • 27
  • 44
  • actually comes empty the second time I consulted a PDF and I think I mentioned earlier, but sorry, I step that detail. but the first time if the data arrives in the querystring and gender pdf – Cristian Saavedra Dec 29 '14 at 15:43
  • is the querystring valorized as you expected? – faby Dec 29 '14 at 15:46
  • fabi, the querystring the first time I want to get the pdf comes with the data, therefore I have no problem pulling out the data, but if I would get the same pdf or another with the same page the querystring is empty, to generate a new pdf I have to close the page and open it again – Cristian Saavedra Dec 29 '14 at 17:11
  • did you try my solution? if you store the value of the querystring in the hiddenfield you can always accessing it – faby Dec 29 '14 at 17:13
  • yes, is implemented but it serves me what I need because the amount of data can vary querystring selecting data from a gridview – Cristian Saavedra Dec 29 '14 at 17:25
  • try saving it in a session variable instead the hiddenfield – faby Dec 29 '14 at 17:29
  • by policies of my company I can not use session variables =( – Cristian Saavedra Dec 29 '14 at 17:34
  • can you use local storage? – faby Dec 29 '14 at 17:35
  • also try passing the data through viewstate but when passing the process of generating the pdf the viewstate in the final product came empty – Cristian Saavedra Dec 29 '14 at 17:36
  • that you mean local storage ?? – Cristian Saavedra Dec 29 '14 at 17:37
  • nothing, it's an html5 feature to store data in webbrowser via javascript. Not what you want probably. What about store it in a cookie? – faby Dec 29 '14 at 17:48
  • I've also tried to pass data in a cookie but this comes empty. when passing through this function as that cookies are lost: byte [] pdfBytes = pdfConverter.GetPdfBytesFromUrl (path); – Cristian Saavedra Dec 29 '14 at 17:54
  • forgive me, I don't understand why you can't use hiddenfield value – faby Dec 29 '14 at 18:00
  • not that you can not use. I explain more clearly, when calling this function that is what creates the pdf: byte [] pdfBytes = pdfConverter.GetPdfBytesFromUrl (path); This loads the code that is at the beginning. revising the code the beginning when I apply the pdf for the first time, the code has no problem, but if I update the page or pressed the button for one second pdf the following line of code: string datosRequest = Request.QueryString ["DATA "]; arrives empty, hence when you follow this process falls on the next line string rutEmpresa = data [3]; – Cristian Saavedra Dec 29 '14 at 18:13
  • since data [3] is empty and there is data associated with that position. Now if I add the hidden field to store the data there in the first instance, this will always have the same data, but if I change the data that comes querystring ?? This will generate the pdf with previous data – Cristian Saavedra Dec 29 '14 at 18:14
  • can you change the hiddenfield value when you change the parameters? maybe with the help of an updatepanel? – faby Dec 29 '14 at 18:43
0

I have solved the problem. I was thinking a bit and detects when passed a second time to obtain the pdf that was creating the cookie to be passed to the other form was created and therefore did not pass the data. for this reason I had to add 2 lines but my code for closing the pdf this server delete the cookie and when consulted again remove the client:

Response.Cookies.Clear ();
myCookie.Expires = DateTime.Now.AddDays (1D);