C# 如何在URL中传递数据

C# 如何在URL中传递数据,c#,javascript,asp.net,post,query-string,C#,Javascript,Asp.net,Post,Query String,如何通过URL传递数据 我需要通行证、电子邮件、客户id等 Client.aspx?Email='teste@gmail.com' 现在我有了一个Javascript函数,但我认为通过代码隐藏会更好 $('.btIncluirAtendimento').live('click', function () { idCliente = $(this).attr('id').replace('cad_', ''); popup = openPopup('../

如何通过URL传递数据

我需要通行证、电子邮件、客户id等

Client.aspx?Email='teste@gmail.com'
现在我有了一个Javascript函数,但我认为通过代码隐藏会更好

    $('.btIncluirAtendimento').live('click', function () {
        idCliente = $(this).attr('id').replace('cad_', '');
        popup = openPopup('../Cliente/AtendimentoNew.aspx?Cliente_Id=' + idCliente, 'IncluirAtendimento', 'toolbar=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=no', '720', '600', 'true');
    });


function openPopup(theURL, winName, features, myWidth, myHeight, isCenter) {
    if (window.screen) if (isCenter) if (isCenter == "true") {
        var myLeft = (screen.width - myWidth) / 2;
        var myTop = (screen.height - myHeight) / 2;
        features += (features != '') ? ',' : '';
        features += ',left=' + myLeft + ',top=' + myTop;
    }
    popup = window.open(theURL, winName, features + ((features != '') ? ',' : '') + 'width=' + myWidth + ',height=' + myHeight);
    return popup;
}

有人能帮我吗?

您需要对url字符串进行编码,这样您就可以轻松地传递数据

例如:

   Server.URLEncode("http://www.w3schools.com?mykey=datavalue");

你在正确的轨道上。首先,URL对值进行编码,如下所示。(编码一个数字不会起任何作用,因此,如果所有客户机ID都是数字,则可以省略第二个UrlEncode。)

这将为您提供以下url:

"Client.aspx?Email=test%40gmail.com&ClientId=1234"
您可以使用以下代码行读取Client.aspx.cs中的值:

string emailAddress = Request.QueryString["Email"];
int clientId = Int32.Parse(Request.QueryString["ClientId"]);

记住检查参数。如果ClientId不是数字,则Int32.Parse()将引发异常。

您必须对关键字符进行编码。寻找对字符的一种删除。您的URL必须如下所示:

Client.aspx?Email=teste%40gmail.com

如果我要传递2个数据?比如,电子邮件和客户?如何进行分离?不应对整个字符串进行编码,而应仅对参数值进行编码,即
“http://www.w3schools.com?mykey=“+Server.URLEncode(“数据值”)@Jan Aagaard-这只是一个例子…好的,展示方法的要点…方法的使用取决于您的需要
Client.aspx?Email=teste%40gmail.com
HttpUtility.UrlEncode(url)