如何通过我的 URL 传递数据?
我需要传递,电子邮件,client_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 编码。 (对数字进行编码不会做任何事情,因此如果所有客户端 ID 都是数字,则可以省略第二个 UrlEncode。)
string url = String.Format("Client.aspx?Email={0}&ClientId={1}",
HttpUtility.UrlEncode("test@gmail.com"),
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() 将抛出异常。
关于c# - 如何在 URL 中传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7820502/