1

I'm trying to send a list of parameters from JS to an asp.net file, but the file is not receiving the parameters correctly. Sometimes I get the message "Undefined". Here's my code:

JavaScript

<script type="text/javascript">

$(document).on("click", "[id*=lnkView]", function () {
    $("#nome").html($(this).closest("tr").find("td.sDisplayName").text());
    $("#Product").html($(this).closest("tr").find(".Produto").text());
    $("#IP").html($(this).closest("tr").find("td.sNetworkAddress").text());
    $("#DC").html($(this).closest("tr").find("td.dc").text());
    $("#comentario").html($(this).closest("tr").find("td.sComment").text());
    $("#inicio").html($(this).closest("tr").find("td.inicio").text());
    $("#mensagem").html($(this).closest("tr").find(".mensagem").text());
    $("#monitor").html($(this).closest("tr").find("td.sMonitorTypeName").text());

    $("#dialog").dialog({
        width: 1000,
        title: "Detalhes para TP",
        buttons: {
            var width = 150;
            var height = 250;
            var left = 99;
            var top = 99;

            var janeleira = window.open("outlookPrimeiro.aspx?" + FIRST VALUE FROM THE FUNCTION ABOVE , 'janela', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no, setTimeout=1000');
            //window.open("outlookPrimeiro.aspx");
            //janeleira.onload = function () { janeleira.setTimeout('janeleira.close()', 1000); }
            //setTimeout(function () { janeleira(); }, 1);
        },

        ok: function () {
            $(this).dialog('close');
        }
    },
    modal: true
    });

    return false;
});

function blinker() {
    $('.blink').fadeOut(500);
    $('.blink').fadeIn(500);
}

setInterval(blinker, 1000); //Runs every second

ASP.NET

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//NECESSÁRIO PARA USAR MARSHALL
using System.Runtime.InteropServices;

//NECESSARIO PARA USAR O OUTLOOK
using aqueleLance = Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;
using testeUsingPrimeiro = Microsoft.Office.Interop.Outlook._AutoFormatRule;
using testeUsingSegundo = Microsoft.Office.Interop.Outlook._AutoFormatRules;
using testeUsingTerceiro = Microsoft.Office.Interop.Outlook.AutoFormatRule;
using testeUsingQuarto = Microsoft.Office.Interop.Outlook.AutoFormatRules;

public partial class outlookPrimeiro : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String nomeDevice = null;
        if (Request.QueryString != null)
        {
            // Seta banco dados 

            nomeDevice = Request.QueryString.ToString();
        }

        //DEFINICICOES DE DADOS DO E-MAIL A SER ENVIADO
        String paraEmail = "[email protected]";
        String copiaEmail = "[email protected]";
        //String copiaOculta = "";
        String assuntoEmail = "Using Outlook 2013";
        String corpo = "<html><body><div style='width:95%;text-align: center;background-color: black'><table style='width: 100%;text-align: center'><tr style='background-color:#5B2E90'><td style='color: white'>Prioridade</td><td style='color: white'>Acionamento</td><td style='color: white'>KBN</td><td style='color: white'>Device</td><td style='color: white'>IP</td><td style='color: white'>DC</td><td style='color: white'>WUG</td><td style='color: white'>Diretorio</td><td style='color: white'>Monitor</td><td style='color: white'>Comentario</td><td style='color: white'>Tempo Down</td><td style='color: white'>Inicio</td><td style='color: white'>TP</td></tr><tr><td style='color: orange'>Prioridade</td><td style='color: orange'>Acionamento</td><td style='color: orange'>KBN</td><td style='color: orange'>"+ nomeDevice + "</td><td style='color: orange'>IP</td><td style='color: orange'>DC</td><td style='color: orange'>WUG</td><td style='color: orange'>Diretorio</td><td style='color: orange'>Monitor</td><td style='color: orange'>Comentario</td><td style='color: orange'>Tempo Down</td><td style='color: orange'>Inicio</td><td style='color: orange'>TP</td></tr></table></div></body></html>";

        //banco(?)
        //string host = "127.0.0.1\SQLEXPRESSNOC";
        //string usuario = "NOME DO USUÁRIO";
        //string senha = "SENHA DO USUARIO";
        //string banco = "NOME DO USUARIO";

        //CRIA NOVO APP USANDO Microsoft.Office.Interop.Outlook.Application
        OutlookApp appDoOutlook = new OutlookApp();

        //CRIA E-MAIL
        aqueleLance.MailItem itemDoMail = appDoOutlook.CreateItem(aqueleLance.OlItemType.olMailItem) as aqueleLance.MailItem;

        //QUAL CONTA VAI ENVIAR?  NECESSÁRIO TER A CONTA NA MÁQUINA
        string nomeDaConta = "[email protected]";

        //CRIA SESSÃO
        aqueleLance.NameSpace sessao = itemDoMail.Session;

        //PEGA CONTAS PRESENTES NA MÁQUINA
        aqueleLance.Accounts contaAccounts = sessao.Accounts;

        //FOR 1 ATÉ FINAL DO NÚMERO DE CONTAS
        for (int i = 1; i <= contaAccounts.Count; i++)
        {
            //aqueleLance.Account contaAccount RECEBE O VALOR DO FOR
            aqueleLance.Account contaAccount = contaAccounts[i];

            //SE A CONTA EXISTE, ELE VAI ENVIAR
            //(COMPARAÇÃO FEITA EM LOWER CASE
            if (contaAccount.DisplayName.ToLower() == nomeDaConta.ToLower())
            {
                //COMANDO PARA ENVIAR USANDO A CONTA XXXXX
                itemDoMail.SendUsingAccount = contaAccount;

                //LIBERA VARIAVEL
                Marshal.ReleaseComObject(contaAccount);

                //PARA O COMANDO
                break;
            }
        }

        //PARA QUEM ENVIA O E-MAIL
        itemDoMail.To = paraEmail;

        //ENVIAR COM COPIA PARA
        itemDoMail.CC = copiaEmail;

        //COPIA OCULTA
        //itemDoMail.BCC = copiaOculta;

        //ASSUNTO DO EMAIL
        itemDoMail.Subject = assuntoEmail;

        //CORPO DO EMAIL EM HTML
        itemDoMail.HTMLBody = corpo;
        //"<html><body>Enviado pelo <strong>Outlook</strong> 2013<br/> Teste do envio com CC e BCC.<br/><br/></body></html>"
        //IMPORTANCIA DO EMAIL
        itemDoMail.Importance = aqueleLance.OlImportance.olImportanceHigh;

        //ENVIA O EMAIL
        //NÃO É POSSÍVEL VER ANTES DE ENVIAR SEM HABILITAR O DISPLAY ABAIXO
        //itemDoMail.Send();

        //HABILITE ISSO PARA VER A MENSAGEM ANTES DE ENVIAR
        //PRECISA TIRAR O SEND ACIMA
        itemDoMail.Display(false);

        //LIBERA CONTAS
        Marshal.ReleaseComObject(contaAccounts);

        //LIBERA SESSÃO
        Marshal.ReleaseComObject(sessao);
    }
}
2
  • Why is the dialog opening a window in the buttons section? What are you trying to do? Commented Mar 22, 2016 at 12:56
  • I´m developing a system which will monitor results of errors in SNMP and send the errors via e-mail to the responsible. The results are listed with the JS that I show above. In ASP i´m trying to get that results to put them in a e-mail. The window.open open a window with a new mail from Outlook 2013 (interop). Commented Mar 22, 2016 at 13:18

1 Answer 1

1

The variables you are posting should be assigned to a parameter. Your querystring doesn't seem to start with a variablename.

Request.QueryString is a collection of variables that you can post.

Request the page like this:

window.open("outlookPrimeiro.aspx?variablename=" + value);

Consecutive variables should be added with the & sign:

window.open("outlookPrimeiro.aspx?variablename=" + value + "&variablename2= " + value2);

On the serverside you can read the variable like this:

string variable = Request.QueryString["variablename"]
Sign up to request clarification or add additional context in comments.

9 Comments

Just to confirm, I have to create variables in my outlookPrimeiro.aspx to receive data from JS, right?
If you send the variablename with page.aspx?abc=123, you can read them serverside with Request.QueryString['abc']. You don't have to create a variable for it.
Ok. I´ll try first creating variables, if this doesn´t work, i´ll try this way. Thanks.
Another question, do you have some idea to how can I get the values from JS? Creating one var to each one?
No. ASP CodeBehind: string nameDoesNotMatter = Request.QueryString["girlsJustWannaHaveFun"]
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.