OnClientClick: losing backslahes in databound filename

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

phillarbyAsked:
Who is Participating?
 
David RobitailleConnect With a Mentor Analyst ProgrammerCommented:
you should replace the "\" with "\\".
0
 
prairiedogCommented:
How about this?
OnClientClick='<%# String.Format("window.open('FileHandler.aspx?fileName={0}')", Eval("FileLocation")%>'

Open in new window

0
 
phillarbyAuthor Commented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
prairiedogCommented:
>>>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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
phillarbyAuthor Commented:
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
 
prairiedogCommented:
Try this: replace the single quote with &#39
0
 
prairiedogCommented:
The single quotes in window.open(&#39.....
0
 
phillarbyAuthor Commented:
The reason for the problem was provided, but no solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.