Link to home
Start Free TrialLog in
Avatar of goodk
goodkFlag for United States of America

asked on

How to pass parameters with spaces to the new page?


I want pass,
City of Dallas  as a parameter.

http://www.myWebsite.com/NewPage?City of Dallas

I only seem to be receiving City.  How to do it right? thanks
Avatar of magicdlf
magicdlf

Make sure you encode the string at first.
http://www.permadi.com/tutorial/urlEncoding/

spaces should be sent as "%20"


http://www.example.com/NewPage?City%20of%20Dallas


however, as mentioned above, anything passed in the url should be encoded properly.

you can simply put this inside quotes, or can use "%20" as space character as mentioned above.
so if you pass it inside an anchor tag, then

<a href="http://www.myWebsite.com/NewPage?City of Dallas">click here</a>

Try It!
Use the escape javascript function

document.location = "http://www.testing.com?" + escape("City of Dallas");
Try using Server.HTMLEncode("City of Dallas")
To pass parameter with spaces is nothing special we can easily get this by:

City of Dallas
use the code i have tried this code:
Avatar of goodk

ASKER

reader.GetName(fcount)="City of Dallas" <-- in database
temphrefstr ="AnyTable.aspx?TableName=AceData&xFieldName=" +sValue1 + "&xFieldValue=" + HttpContext.Current.Server.HtmlEncode(reader.GetName(fcount)) + "&xFieldName1=" + sValue2 + "&xFieldValue2=" + hArray[fcount];
hrefstr = "<a href=" + temphrefstr + ">" + tmpreader + InvestmentClosedDate + "</a>";
 
I only see City instead of City of Dallas
http://localhost:58297/Prod/AnyTable.aspx?TableName=AceData&xFieldName=Job&xFieldValue=City 
 
please help! thanks
 

 
Insert this:
temphrefstr =  Server.HTMLEncode("temphrefstr");
ASKER CERTIFIED SOLUTION
Avatar of code-colors
code-colors
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's an update. Use this will be correctly solve your issue.
hrefstr = "<a href=" + HttpUtility.UrlEncode(temphrefstr) + ">" + tmpreader + InvestmentClosedDate + "</a>";
hi dear i have tried this code which is working for me the same thing

string strq = "City of Dallas";
        lbllink.Text = "http://www.myWebsite.com/NewPage?city=City of Dallas";
hi dear i have tried this code which is working for me the same thing

string strq = "City of Dallas";
        lbllink.Text = "<a href=\"http://www.myWebsite.com/NewPage?city=" + strq + "\">http://www.myWebsite.com/NewPage?city=City of Dallas</a>";
string strq = "City of Dallas";
        lbllink.Text = "<a href=\"http://www.myWebsite.com/NewPage?city=" + strq + "\">http://www.myWebsite.com/NewPage?city=City of Dallas</a>";

Open in new window

Avatar of goodk

ASKER

http://localhost:58297/Prod/AnyTable.aspx?TableName=AceData&xFieldName=Job&xFieldValue=CCncr&xFieldName1=PayedTo&xFieldValue2=ACE PBNB Account
ok, on the receiving end do i have to do anything special. or just something like this? please help! thanks

if (Request.QueryString["xFieldValue2"] != null)
  string xWhere = "Where " + xFieldName1 + "='" + xFieldValue2 + "'"