Calling Asp.net application via HTML page

Asked

Viewed 1,588 times

5

I have an app that I can’t change the source code that generates purchase orders. For each request an html is stored with the request data. I want to implement this html with the following: When opening html, embed a simple page in Asp.net that will bring information and a link corresponding to the number of that request.

The template of HTML currently generated is the following:

<TABLE width="100%" bordercolorlight="#000000" border="1">
 <TBODY>
   <TR>
      <!--TD style="WIDTH: 112px">
          <P align=left><img border="0" src=!wf_link!images/logo.jpg></P>
      </TD-->
      <td style="text-align: left; vertical-align: middle; width: 18%;">
          <img style="width:auto; text-align:center; vertical-align:middle; height:auto;" src=!wf_link!images/logo.jpg>
      </td>

      <td style="WIDTH: 866px; TEXT-ALIGN: center">
          <p><font size="3"><b>SOLICITAÇÃO DE COMPRAS Nr. %NUMSC% (Filial %FILIAL%)</b></font> // campo que preciso obter na minha consulta ao banco
      </td>

      <td style="WIDTH: 300px">
          <dl>
              <div align="left">
                  <dt><font><b>Cód. Aprov.:</b></font>
                      <FONT color=#000000 face="Verdana">
                          <SPAN class=style7 style="font-weight: 400">%CAMPO2%</span>
                      </FONT>
                  </dt>
                  <dd>
                  <dt><b><font align="left">Nome:</font></b>
                      <FONT color=#000000 face="Verdana">
                          <SPAN class=style7 style="font-weight: 400">%CAMPO3%</span>
                      </FONT>
                  </dt>
              </div>
          </dl>
      </td>

  </TR>

The Asp.net page that I wish to incorporate into the code:

<script runat="server">
        protected void Page_Load(Object Src, EventArgs E)
        {

            string host = "****";
            string usuario = "****";
            string senha = "****";
            string banco = "****"; 


  string strSQL = "SELECT codigo, arquivolink from MinhaTabela"; // Aqui eu preciso dar um where pegando o campo %NUMSC% do HTML

            SqlConnection conexao = new SqlConnection("Data Source=" + host + ";DATABASE=" + banco + ";UID=" + usuario + "; PWD=" + senha + ";");

                conexao.Open();

                    SqlCommand comando = new SqlCommand(strSQL, conexao);
                    SqlDataReader dr = comando.ExecuteReader();

                        Response.Write("<table border='1'>");

                            for (int i = 0; i < dr.FieldCount; i++)
                            {
                                Response.Write("<th>" + dr.GetName(i) + "</th>");
                            }

                            while (dr.Read())
                            {
                                Response.Write("<tr>");
                                    for (int i = 0; i < dr.FieldCount; i++)
                                    {
                                        Response.Write("<td align='center'>" + dr.GetValue(i) + "</td>");
                                    }
                                Response.Write("</tr>");
                            }
                        Response.Write("</table>");

                    dr.Close();
                    dr.Dispose();
                    comando.Dispose(); 

                conexao.Close();
                conexao.Dispose();

        }
    </script>

What I need is that when I open the HTML page I see below everything, the information coming from these scripts that would be the number and the file referring to that invoice number. Since this file name will be a link to open an attachment (pdf, txt, etc) that will be in a folder of my application server.

Do I need to have this distinct page/application? How do I get a certain html field in my database query?

1 answer

1

Format your URL to pass the fields at source:

 < form method="post" action="http:/ / servidor/aplicativo/Pagina.aspx">
<TABLE width="100%" bordercolorlight="#000000" border="1">
<TBODY>
<TR>
  <!--TD style="WIDTH: 112px">
      <P align=left><img border="0" src=!wf_link!images/logo.jpg></P>
  </TD-->
  <td style="text-align: left; vertical-align: middle; width: 18%;">
      <img style="width:auto; text-align:center; vertical-align:middle; height:auto;" src=!wf_link!images/logo.jpg>
  </td>

  <td style="WIDTH: 866px; TEXT-ALIGN: center">
      <p><font size="3"><b>SOLICITAÇÃO DE COMPRAS Nr. %NUMSC% (Filial %FILIAL%)</b></font> // campo que preciso obter na minha consulta ao banco
          <input type="hidden" name="NumeroCompra" value="%NUMSC%" />
          <input type="hidden" name="Filial" value="%FILIAL%" />
  </td>

  <td style="WIDTH: 300px">
      <dl>
          <div align="left">
              <dt><font><b>Cód. Aprov.:</b></font>
                  <FONT color=#000000 face="Verdana">
                      <SPAN class=style7 style="font-weight: 400">%CAMPO2%</span>
                      <input type="hidden" name="CodAprov" value="%CAMPO2%" />
                  </FONT>
              </dt>
              <dd>
              <dt><b><font align="left">Nome:</font></b>
                  <FONT color=#000000 face="Verdana">
                      <SPAN class=style7 style="font-weight: 400">%CAMPO3%</span>
                      <input type="hidden" name="Nome" value="%CAMPO3%" />
                  </FONT>
              </dt>
          </div>
      </dl>
  </td>

  </TR>
 <  /  TABLE >
 < / form>

And in Your Forml_load capture this field

var Compra = Request.Form["NumeroCompra"];
var Filial = Request.Form["Filial"];
  • I’m sorry @Fernandonomellini, I don’t get it. How do I get the fields through the url? I need to get a number coming from html and get it in the Where of the sql query, as I apply your answer to this?

  • Does your html have a FORM ? If yes, the fields should be in <input s> in the form and ai instead of Request.Querystring["Name"] you would use Request.Form["Name"]

  • There’s nothing ready to allow extract a value of an html. You pass values either by Querystrings or by Forms. Otherwise, you should seek a solution on another, more complex level.

  • It’s not a form no... it’s just this table I passed. In case I would have to edit my html to turn it into a form?

  • If you can edit HTML to become FORM, then it would be easy.

  • in the form Actin you indicate your site Asp.net example <form method=post action=http: / / meuserver/application/page.aspx> <input type Hidden value = "value1" name = "field1"> </form>

  • but in this case this html is a template that generates other htmls each with the corresponding number of the purchase in which is obtained by the variable %NUMSC%. This template takes this number from a database and generates the final html. Can I still apply the form - input? Because it’s not a manual insertion field

  • I changed my answer

  • So my html is going to point to my Asp page and not the other way around? in my html I just need to put at the top the reference to the Asp.net scritp I passed in the question? what in the case Voce called Pagina.aspx ?

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.