Reputation: 4261
how can i pass the value of my querystring into javacript ? that mean get the querystring on curent windows value and pass it into javascript to open a new page.
ex.: /FicheClient.aspx?Item=Tarif&Id=850001
i want to pass Id=850001 into window.open('Tarif_Report.aspx?Id=????')
<dx:ASPxButton ID="ASPxButton_RptTarif" runat="server" Text="Voir" AutoPostBack="False">
<ClientSideEvents
Click="function (s, e) { e.processOnServer = false; window.open('Tarif_Report.aspx?Id=????'); }" />
</dx:ASPxButton>
thanks you in advance. Stev
Upvotes: 0
Views: 981
Reputation: 1450
Upvotes: 0
Reputation: 4261
i got it:
<script type="text/javascript">
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
<dx:ASPxButton ID="ASPxButton_RptTarif" runat="server" Text="Voir" AutoPostBack="False">
<ClientSideEvents
Click="function (s, e) { e.processOnServer = false; window.open('../Tarif_Report.aspx?ClientID=' + getParameterByName('Id')); }" />
</dx:ASPxButton>
Thanks you all
Upvotes: 0
Reputation: 107
/*
* <summary>
* Get the querystring value
* </summary>
* <param name="key">A string contains the querystring key</param>
* <param name="defaultVal">Object which get returns when there is not key</param>
*
*/
function getQuerystring(key, defaultVal) {
if (defaultVal == null) {
defaultVal = "";
}
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
var qs = regex.exec(window.location.href);
if (qs == null) {
return defaultVal;
}
else {
return qs[1];
}
}
try This.
Upvotes: 1
Reputation: 3523
You can get a hold of the url using window.location.search
Check How can I get query string values in JavaScript? for a good answer for parsing the Querystring into something useful.
So with that you can access your param by going
window.open('/Tarif_Report.aspx?Id=' + urlParams["Id"]);
Upvotes: 0
Reputation: 5727
Store the value of QueryString in Label or HiddenField, and get the stored value from document.getElementById('Label').value. Pass this value in the window.open url.
Upvotes: 0