Solved

pass value through URL?

Posted on 2008-10-31
24
279 Views
Last Modified: 2008-11-17
Hello Experts

I'm having trouble with something I use all the time.  I have an RS report that uses a navigation field for passing a value through to a .net program I use.  Here is the navigation link we currently use:

="javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum=" & Fields!Expr2.Value & "','_blank'))"

This was going well until I tried passing through Expr2.Value.  This field contains names of customer shops like "John Doe's Parts Co." or "J. Doe's Parts (City Name)".  The javascript I use can't handle "  '  " or  " . " at all, it just gives me a script error on the report when I try to click the navigation link.  For the links that don't contain apostrophes or periods it works.  In the .net program I simply use this to get the correct value:

Sub UrlDecode()
        Dim s, param As String
        Dim i As Integer
        s = Request.RawUrl
        i = s.LastIndexOf("=")
        param = s.Substring(i + 1, s.Length - i - 1)
        param = Server.UrlDecode(param)
        mystr = param
End Sub

Is there a way to edit that javacript link so it works with all characters no matter what appears after /webform1.aspx?ctrlnum=    ?
Help!
0
Comment
Question by:jay-are
  • 11
  • 10
  • +2
24 Comments
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22851064
0
 
LVL 16

Expert Comment

by:brad2575
ID: 22851081
Not it will not work like that because the URL can not contain those characters.  

Try using an ID (if possible) for the name in a database table, or before it is put in the URL do what you are doing in the UrlDecode BEFORE it is added to the URL query string.

0
 
LVL 16

Expert Comment

by:robinu
ID: 22851098
Can you use the UrlEncode function on the page http://www.albionresearch.com/misc/urlencode.php ?
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22851104
0
 

Author Comment

by:jay-are
ID: 22851149
Well the javascript link is used in a Reporting Services report.  As far as I know there is no way to add VB code to a report.
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22851209
To convert a string to the URL-encoded form suitable for transmission as a query string (or, generally speaking, as part of a URL), use the escape function.

http://www.javascripter.net/faq/escape.htm
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22851245
http://www.dynamicsitesolutions.com/javascript/url-encoding/

click browser view source to get the souce code
0
 

Author Comment

by:jay-are
ID: 22853479
So would I try something like this?

="javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum=" & javascript:void(escape(Fields!Expr2.Value)) & "','_blank'))"

I tried putting the second javascript:void in "" and it still gives me an error.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22855448
The problem is, you need to ESCAPE it when sending via the URL and then UNESCAPE it when the other page receives it -- a 2 step process, normally speaking.  If you cannot run functions on both pages to do this, you will have to pack it into the strings ... either way, and escape() sending and an unescape() receiving, or the equivalent, should get rid of the error.
0
 

Author Comment

by:jay-are
ID: 22857503
Well I don't think my link is correct which is why I get the error "Expected end of statement ')'".

0
 

Author Comment

by:jay-are
ID: 22868219
Any ideas?  Am I using escape() properly in the link?
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22868236
try

="javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum=" & (escape(Fields!Expr2.Value)) & "','_blank'))"
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jay-are
ID: 22868271
[rsCompilerErrorInExpression] The Hyperlink expression for the textbox textbox11 contains an error: [BC30451] Name 'escape' is not declared.

0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22868333
oops

could it be possible to create one variable and assign the escape value to it and then use the variable

which reporting tool you are using

Fields!Expr2.Value -- is your code is in vb.net

0
 

Author Comment

by:jay-are
ID: 22868359
Just using VS05 to create the RS reports.  Create a new field using escape()?  Something like
escape(Fields!Expr2.Value)  and call it Fields!Whatever.Value

?
0
 

Author Comment

by:jay-are
ID: 22868454
When I try to create a column like that it just literally puts in 'escape(Fields!Expr2.Value)' .  
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22868690
try

replace
="javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum=" & Fields!Expr2.Value & "','_blank'))"


with

="javascript:var str;str ='../arparentnotes/webform1.aspx?ctrlnum='+ escape(" & Fields!Expr2.Value & ");void(window.open(str,'_blank'))"

or

="javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum=' + escape(" & Fields!Expr2.Value & ") + ','_blank'))"
0
 

Author Comment

by:jay-are
ID: 22869627
Both of those end up looking like this:

javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum='%20+%20escape(AUTO%20BATTERY%20&%20IGNITION)%20+%20','_blank'))

Both give ")" expected end of statement errors.
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22870839
could it be possible for you to call the javascript function instead of directly calling the window.open
0
 

Author Comment

by:jay-are
ID: 22870883
Well I need the window.open so that the program opens in a new window, unless you know another way of doing that.
0
 
LVL 7

Expert Comment

by:ASPSQLServerCOM
ID: 22871187
try


="javascript:void(window.open('../arparentnotes/webform1.aspx?ctrlnum=" & Server.HTMLEncode(Fields!Expr2.Value) & "','_blank'))"
 

or 

check the field property, does it has 

htmlencode then set it to "true"
 

if this doesnt work then in SQL while retrieving data at that time only you can write some function which encode the data

Open in new window

0
 

Author Comment

by:jay-are
ID: 22871255
The Hyperlink expression for the textbox textbox11 contains an error: [BC30451] Name 'Server' is not declared.

So that doesn't work either since it won't recognize Server.HTMLEncode().  How do I do this on the sql side?
0
 
LVL 7

Accepted Solution

by:
ASPSQLServerCOM earned 500 total points
ID: 22871414
other way is like
create one function in SQL which will do same functionality as HTML

example - (but this does not have the ready made function, I think you have to write or search )
http://support.microsoft.com/kb/246069

then in your select statement use this function to return the encoded data
0
 

Author Comment

by:jay-are
ID: 22979490
I'm still working on this one but having trouble.  Will post again later if I can't get it to work.  Thanks for the help.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now