?
Solved

OnClientClick: losing backslahes in databound filename

Posted on 2008-11-19
9
Medium Priority
?
324 Views
Last Modified: 2012-05-05
I'm trying to open files from a linkbutton in a gridview using databound filenames by calling a filehandler.aspx page from OnClientClick as per the attached code. The filehandler.aspx window opens fine, but I'm having a problem with losing backslashes in the filename

For example, the url in the new window should be:
[..]/FileHandler.aspx?fileName=\\brkascssql\SERF_FILES\CEMTest\GB311008141857PL\test.txt
but I get:
[..]/FileHandler.aspx?fileName=\brkascssqlSERF_FILESCEMTestGB311008141857PLest.txt

Can anyone help?

<asp:LinkButton
ID="QuoteFileDescription"
runat="server"
Text='<%# Eval("Description") %>'
OnClientClick='<%# Eval("FileLocation","window.open(\"FileHandler.aspx?fileName={0}\")")%>' />

Open in new window

0
Comment
Question by:phillarby
  • 4
  • 3
  • 2
9 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 1500 total points
ID: 22994853
you should replace the "\" with "\\".
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22994924
How about this?
OnClientClick='<%# String.Format("window.open('FileHandler.aspx?fileName={0}')", Eval("FileLocation")%>'

Open in new window

0
 

Author Comment

by:phillarby
ID: 22995158
Prariedog.  This gives me a 'The Server tag is not well formed' error.

davrob60.  I'm not able to change the format of the filenames in teh DB if that is what you mean?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Expert Comment

by:prairiedog
ID: 22995209
>>>Prariedog.  This gives me a 'The Server tag is not well formed' error.

It shouldn't do that. But remember though, I didn't include the close tag ("/>") for the LinkButton definition, the one I gave you is just for OnClientClick portion.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22995340
I gave you the explanation why the \ are loose. you got to replace them with something like :
Eval("FileLocation").tostring().replace("\", "\\")
But Prariedog`s solution will prevent others error from others specials char.
you may got your 'The Server tag is not well formed' error. because of the '
("window.open('FileHandler.aspx?fileName={0}')"
you may try  
("window.open(""FileHandler.aspx?fileName={0}"")"
0
 

Author Comment

by:phillarby
ID: 22995436
Not sure what the probelm is, but I still get 'The Server tag is not well formed'.

For the time being I have reliased that I am able to manipulate the filename from the DB as the datasource for the grid is an ObjectDataSource, so it is up and running, but I would prefer the String.Format approach if I can get to the bottom of this problem!
<asp:LinkButton ID="QuoteFileDescription" 
runat="server" 
Text='<%# Eval("Description") %>' 
OnClientClick='<%# String.Format("window.open('FileHandler.aspx?fileName={0}')", Eval("FileLocation")%>' />

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22995462
Try this: replace the single quote with &#39
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22995470
The single quotes in window.open(&#39.....
0
 

Author Closing Comment

by:phillarby
ID: 31518254
The reason for the problem was provided, but no solution.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 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