how to pass the space and special character in query string RRS feed

  • Question

  • User1587720337 posted

    I am trying to pass the values with space and special characters for parameter tbResponse and tbDescription field, but its throwing an error. Any ideas how to fix thsi?

    here is the code:

    document.getElementById("myLnk").href = "updateKeywordImageDialog.aspx?isUpdate=1&tbKeyword=" + tbKeyword + "&tbLimit=" + tbLimit + "&ddlGroup=" + ddlGroup + "&tbResponse=" + tbResponse + "&tbDescription=" + tbDescription + "&chkActive=" + chkActive + "&tbExpiryDate=" + tbExpiryDate + "";

    Error Message:

    Uncaught Error: Syntax error, unrecognized expression: for your Inquiry into sudhir bharti For more information &tbDescription=&chkActive=true&tbExpiryDate=01/08/2021

    Tuesday, April 14, 2020 4:58 AM

All replies

  • User-719153870 posted

    Hi sudhir.bharti,

    I am trying to pass the values with space and special characters for parameter tbResponse and tbDescription field, but its throwing an error.

    I don't think you can contain a blank space in your url, see URLs cannot contain spaces.

    The issue can not be reproduced, can you provide more code so that we can reproduce it?

    Below is the demo i used to test:


    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
            function load() {
                var tbKeyword = "a\ a%&%!@#$%^&*()(*&^%";
                var tbLimit = "";
                var ddlGroup ="01/08/2021"
                var myLnk = document.getElementById("myLnk");
                myLnk.href = "About.aspx?isUpdate=1&tbKeyword=" + tbKeyword + "&tbLimit=" + tbLimit + "&ddlGroup=" + ddlGroup;// + "&tbResponse=" + tbResponse + "&tbDescription=" + tbDescription + "&chkActive=" + chkActive + "&tbExpiryDate=" + tbExpiryDate + "";
    <body onload="load()">
        <form id="form1" runat="server" >
                <a id="myLnk">asdas</a>



    As you can see the blank space will be automatically converted to %20.

    Best Regard,

    Yang Shen

    Tuesday, April 14, 2020 6:53 AM
  • User1587720337 posted

    Thanks for the response. it's not working for a special character no  (e.g. sudhir bharti & %) , for space i used the replace function to replace the space to underscore, but now its failing on the special character. is there a way to by which we can allow the special character with space in url.


    function UpdateLink() {

    var tbResponse = document.getElementById('ChildContentHolder_tbResponse').value;

    tbResponse = tbResponse.replace(" ", "_");

    document.getElementById("myLnk").href = "updateKeywordImageDialog.aspx?&tbResponse=" + tbResponse + "";


    <a id="myLnk" href="#" title="Add Media(s)" data-target="#theModalAnswer" data-toggle="modal" onclick="UpdateLink();">
    <label for="email1" class="control-label" style="font-size: 16px !important; text-align: right !important; " title="Add or Remove Image Media Max of (5) images or a total media payload < 600Kb">Media (+/-):</label></a>

    on another cs page, i am trying to cature the querystring as below

    Session["tbResponse"] = Convert.ToString(Request.QueryString["tbResponse"]);

    but its throwing an error when there is any special character.

    any ideas how to allow the specail characters as well.

    Tuesday, April 14, 2020 7:14 AM
  • User409696431 posted

    You need to URLEncode your parameters before creating your URL, if they contain special characters or spaces. (If you do that you don't need to replace spaces with underlines either.)



    string destinationURL = "http://www.contoso.com/default.aspx?user=test";
    NextPage.NavigateUrl = "~/Finish?url=" + Server.UrlEncode(destinationURL);

    When you request the parameter, URLDecode it.



    string returnUrl = Server.UrlDecode(Request.QueryString["url"]);

    Thursday, April 16, 2020 1:46 PM
  • User-158764254 posted

    note that when you read the values back in using Requst.QueryString[], they will be automatically passed through HttpUtility.UrlDecode

    Thursday, April 16, 2020 6:41 PM
  • User409696431 posted

    It's interesting that the Microsoft documentation I quoted does not assume that to be true.  The examples were from those links.

    Thursday, April 16, 2020 11:31 PM