0

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

5 Answers 5

1
 /*
* <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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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"]);

Comments

0

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

Comments

0
  1. Create a public property in page.
  2. During page load event set that property by getting the value from query string.
  3. In ASPX page get the value using <% = this.PropertyName; %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.