I am in need of assistance with a javascript function that returns an array.
My main queries are:
- (a) How can I call the Javascript function during OnInit or Onload?
- (b) The javascript function outputs an array, and I would like to store it within an array in my c# code.
Your suggestions would be greatly appreciated.
Thank you.
Update1: Below is an example of the Javascript function:
function RenderUrl()
{
var url = "http://myurl.com/mypage?Id=420&Width=30"; //this is a sample 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;
}
Update 2: Here is the current status of my c# code (not producing desired results yet, but still under review)
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);
}
//Code for adding elements to the new PARAMS array here (work in progress)
..
..
//End of array construction.
matches = rgx.Matches(Url);
}
//Once everything is working properly, the array will be returned.
}