Issue related scope of a variable [Resolved]

Posted by Amatya under JavaScript on 2/17/2016 | Points: 10 | Views : 393 | Status : [Member] | Replies : 6
I have a variable in A.aspx page in function A(), say temp = 2; Now i want this variable in B.aspx page in function B(). I tried much, but iam unable to get the variable value. Do reply if anyone know . Thanks in Advance

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks



Responses

Posted by: A2H on: 2/17/2016 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
As mentioned by RajNilari you can use Querystring to pass values between pages and To read the values from Querystring and then assign it in your Javascript function. if that is the case then you can use the below code to get the values from querystring in Javascript.

function getParameterByName(name) {

name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexString = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexString);
var found = regex.exec(window.location.search);
if (found == null)
return "";
else
return decodeURIComponent(found[1].replace(/\+/g, " "));
}


You can then use above code like below if you querystring value is
Response.Redirect("B.aspx?temp=2");

 //get the Temp value

var tempValue = getParameterByName("temp");



source url : http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript?page=1&tab=votes#tab-top

Thanks,
A2H
My Blog

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 2/17/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Amatya Sir, since you tagged as Javascript, so pass that as a query parameter from A.aspx

e.g.
window.location.href = "B.aspx?temp=2"


However if you are passing that variable from Code behind then please use (in A.aspx)

Response.Redirect("B.aspx?temp=2");


and in page B.aspx accept the temp using QueryString . e.g.

protected void Page_Load(object sender, EventArgs e)

{
string v = Request.QueryString["temp"];
if (v != null)
{
Response.Write(v);
}
}


Hope that helps

--
Thanks & Regards,
RNA Team

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/17/2016 [Member] Silver | Points: 25

Up
0
Down
I want in B.aspx not in B.aspx.cs page.

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/17/2016 [Member] Silver | Points: 25

Up
0
Down
 function SelectFeature()
{


var layerSelect = document.getElementById("layerSelect");
var resultSelect = document.getElementById("resultSelect");

reqParams = "COMMAND=<%=Command.GETSELECTIONXML%>";
reqParams += "&SESSION=" + encodeURIComponent(session);
reqParams += "&MAPNAME=" + encodeURIComponent(mapName);
reqParams += "&LAYERNAME=" + encodeURIComponent(layerSelect.value);
reqParams += "&IDLIST=" + results[resultSelect.value].idList.toJSONString();

if (msie)
reqHandler = new ActiveXObject("Microsoft.XMLHTTP");
else
reqHandler = new XMLHttpRequest();

reqHandler.open("POST", "querycontroller.aspx", false);
reqHandler.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
reqHandler.send(reqParams);
selectionXml = reqHandler.responseText;
parent.parent.mapFrame.SetSelectionXML(selectionXml);
//Response.Redirect("MapViewer.aspx?temp=2");
}


This is my javascript function where i have to declare temp variable. This is my A.aspx page .

Now,

function OpenQueryBuilder() {
debugger
//
//tempZ = 2;
//tempVar = 1;
ExecuteCmd(14);

if (checkForMapFrame() == false) return;
if (MGFrame.contentWindow != null && MGFrame.contentWindow.mapFrame != null) {
MGFrame.contentWindow.GetTaskFrame().frames[1].location.href = "query/querymain.aspx?SESSION=" + MGFrame.contentWindow.mapFrame.GetSessionId() + "&MAPNAME=" + MGFrame.contentWindow.mapFrame.GetMapName();
//MGFrame.contentWindow.GetTaskFrame().frames[1].bgColor = "White";
}
else {
MGFrame.GetTaskFrame().frames[1].location.href = "query/querymain.aspx?SESSION=" + MGFrame.mapFrame.GetSessionId() + "&MAPNAME=" + MGFrame.mapFrame.GetMapName();
}
return;
}


In the above function, which is in my say b.aspx i have to get the value of passed variable value




Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 2/17/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
OK. So in that case get the URL and parse that to get the key (which is temp) and the value (temp value).
Here is an example

var uRL= window.location.search;
uRL= uRL.split("?")[1].split("=")[1];


You can also refer this site ( http://dotnetprof.blogspot.in/2012/11/get-querystring-values-using-javascript.html ) which implements the full code.

Hope this helps.


--
Thanks & Regards,
RNA Team

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/17/2016 [Member] Silver | Points: 25

Up
0
Down
I didnt got dear.. Still struggling

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response