Why don't we pass the query string to web method and just the redirect to the page you want in aspx page .Lets have a look !!!
In *.aspx
<script>
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(function() {
//q=QueryString Name
var id = getParameterByName('q');
console.log(id);
//if (id === null) {
// id = "test";
// }
var data = JSON.stringify({ ID: id });
$(document).ready(function () {
$.ajax({
type: "POST",
url: "*.aspx/showOrders",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
var d = data.d;
window.location = "Default2.aspx?id=" + d;
}
});
});
});
</script>
and in *.aspx.cs
[WebMethod]
public static String showOrders(String ID)
{
//Do some work an logic here
return ID;
}
and .aspx page Complete page
<div>
<asp:Button ID="showOrderbtn" runat="server" Text="ShowOrder"
ClientIDMode="Static"/>
</div>
<script>
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(function() {
$('#showOrderbtn').on('click', function(e) {
e.preventDefault();
alert('In button click');
var id = getParameterByName('q');
console.log(id);
if (id === null) {
id = "test";
}
var data = JSON.stringify({ ID: id });
$.ajax({
type: "POST",
url: "IframeWithPowerBi.aspx/showOrders",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var d = data.d;
window.location = "Default2.aspx?id=" + d;
}
});
});
});
</script>