Link to home
Start Free TrialLog in
Avatar of phillarby
phillarby

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of David Robitaille
David Robitaille
Flag of Canada 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
How about this?
OnClientClick='<%# String.Format("window.open('FileHandler.aspx?fileName={0}')", Eval("FileLocation")%>'

Open in new window

Avatar of phillarby
phillarby

ASKER

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?
>>>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.
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}"")"
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

Try this: replace the single quote with &#39
The single quotes in window.open(&#39.....
The reason for the problem was provided, but no solution.