如何在 URL 中传递数据

发布于 2024-12-10 21:08:23 字数 1161 浏览 0 评论 0原文

如何通过我的 URL 传递数据?

我需要传递电子邮件、client_id 等。

Client.aspx?Email='[email protected]'

现在我有一个 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;
}

有人能帮助我吗?

How can I pass data through my URL ?

I need to pass, an email, client_id, etc.

Client.aspx?Email='[email protected]'

Nowadays I have an Javascript Function, but I think would be better via Code-Behind

    $('.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;
}

Can anyone help me ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

何止钟意 2024-12-17 21:08:23

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

string url = String.Format("Client.aspx?Email={0}&ClientId={1}",
    HttpUtility.UrlEncode("[email protected]"),
    HttpUtility.UrlEncode("1234"));

这将为您提供以下 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() 将抛出异常。

You are on the right track. First, URL-encode the values, like this. (Encoding a number will not do anything, so the second UrlEncode could be left out if all client IDs are numbers.)

string url = String.Format("Client.aspx?Email={0}&ClientId={1}",
    HttpUtility.UrlEncode("[email protected]"),
    HttpUtility.UrlEncode("1234"));

This will give you this url:

"Client.aspx?Email=test%40gmail.com&ClientId=1234"

You can read the values in Client.aspx.cs with these line of code:

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

Remember to check parameters. Int32.Parse() will throw an exception if ClientId is not a number.

情定在深秋 2024-12-17 21:08:23

您需要对 url 字符串进行编码,然后才能轻松传递数据。

例子 :

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

You need to encode the url string and than you can pass data easily.

Example :

   Server.URLEncode("http://www.w3schools.com?mykey=datavalue");
甲如呢乙后呢 2024-12-17 21:08:23

您必须对关键字符进行编码。请在此处查看字符说明。您的网址必须如下所示:

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

You'll have to encode the critical characters. Look here for a desacription the characters. Your URL has to look like this:

Client.aspx?Email=teste%40gmail.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文