javascritp problem... handling special char.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello...

i've got a javascript problem...
my url is created dynamically something like

DeptDetail2.aspx?SubOrgNm=" + SubOrgNm + "&OrgId=" + OrgId + "&SubOrgId=" +
SubOrgId

my problem is that when e.g. suborgnm have the special char of "&" it does
not save this value.. e.g my value would be like this "M&M" it only save M

how can i solve this problem? thanks
 
Hi Asha,

You need to escape the name to prevent the reserved characters from getting
on the querystring. Use Server.UrlEncode() as shown below?

Dim SubOrgNm As String = "M&M"
Dim OrgId As Integer = 5
Dim SubOrgId As Integer = 10
Response.Redirect("DeptDetail2.aspx?SubOrgNm=" +
Server.UrlEncode(SubOrgNm) + "&OrgId=" + OrgId.ToString + "&SubOrgId=" +
SubOrgId.ToString)

It creates something that looks like this:

DeptDetail2.aspx?SubOrgNm=M%26M&OrgId=5&SubOrgId=10

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
Back
Top