如何通过我的网址传递数据?
我需要传递,发送电子邮件,client_id等。
Client.aspx?Email='teste@gmail.com'
现在我有一个Javascript函数,但我认为通过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;
}
任何人都可以帮助我吗?
答案 0 :(得分:2)
你走在正确的轨道上。首先,对这些值进行URL编码,如下所示。 (编码数字不会做任何事情,因此如果所有客户端ID都是数字,则可以省略第二个UrlEncode。)
string url = String.Format("Client.aspx?Email={0}&ClientId={1}",
HttpUtility.UrlEncode("test@gmail.com"),
HttpUtility.UrlEncode("1234"));
这会给你这个网址:
"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()将抛出异常。
答案 1 :(得分:1)
您需要对url字符串进行编码,而不是轻松传递数据。
示例:
Server.URLEncode("http://www.w3schools.com?mykey=datavalue");
答案 2 :(得分:0)
您必须对关键字符进行编码。查看here对角色的描述。您的网址必须如下所示:
Client.aspx?Email=teste%40gmail.com
答案 3 :(得分:0)
HttpUtility.UrlEncode(url)