배열을 반환하는 javascript 함수가 있습니다.javascript의 반환 값을 C#의 배열에 할당해야합니다.
내가 알고 싶습니다
- (가) 어떻게하는 OnInit 또는 온로드 에서 자바 스크립트 함수를 호출하는
- (b)에 자바 스크립트 함수는 배열을 반환하고 나는 그것이 배열 내에 저장할 내 C# 코드.
좋습니다.
감사합니다.
업데이트 1 : 자바 스크립트 기능은 다음과 같습니다.
function RenderUrl()
{
var url = "http://myurl.com/mypage?Id=420&Width=30"; //this is a dummy url.
var qsBegin = url.indexOf("?");
var qsPattern = new RegExp("[?&]([^=]*)=([^&]*)", "ig");
var match = qsPattern.exec(url);
var params = new Array();
while (match != null)
{
var matchID = match[1];
if (matchID.charAt(0) == "&")
{
matchID = matchID.substr(1);
}
if (params[match[1]] != null && !(params[match[1]] instanceof Array))
{
var subArray = new Array();
subArray.push(params[match[1]]);
subArray.push(unescape(match[2]));
params[match[1]] = subArray;
}
else if (params[match[1]] != null && params[match[1]] instanceof Array)
{
params[match[1]].push(unescape(match[2]));
}
else
{
params[match[1]]=unescape(match[2]);
}
match = qsPattern.exec(url);
}
return params;
}
업데이트 2 : 내 C# 코드까지 (예상대로 작동하지만 현재 확인하고되지 않음) I, 당신은 서버 측 코드에서 클라이언트 측 코드를 호출 할 수 없습니다 확인
private void ParseUrl(string Url)
{
int WhereToBegin = Url.IndexOf("?");
string pattern = @"[?&]([^=]*)=([^&]*)";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(Url);
while (matches != null)
{
string matchID = matches[0].ToString();
if (matchID.Substring(0, 1) == "&")
{
matchID = matchID.Substring(1);
}
//Push to the new array named PARAMS here (under construction)
..
..
//End array construction.
matches = rgx.Matches(Url);
}
//Finally return the array once it is working fine.
}
나는 당신이 말하는 것이 합리적이지 않습니다. CLIENT 컴퓨터에서 페이지가로드 될 때 실행할 자바 스크립트 코드 (CLIENT 컴퓨터에서 실행되는 코드)가 있는데 어떻게 든 그 데이터 배열을 SERVER로 반환합니까? 아마도 당신이하려는 일에 대해 더 설명해야 할 것입니다. – ean5533
좀 더 자세한 정보를 추가 할 수 있습니까? 자바 스크립트 기능이란 무엇입니까? 그리고 정확히 무엇을하고 싶니? – Tallmaris
당신은 포스트에 자바 스크립트에서 데이터를 얻을 수 ...이게 당신에게 좋은가요? – Aristos