OnClinetClick and window.open

Why doesn't my OnClientClick event work?

Here' my asp.net 2.0 code:
                                <td>Map Page</td>
                                <td><asp:TextBox ID="txtMapPage" runat="server" Text='<%# Eval("MapPage") %>' width="50"  ReadOnly="true" />
                                &nbsp;&nbsp;<asp:Button ID="btnViewMapPage" runat="server"
                                            CommandName = "ViewMapPage"
                                            Text="View"
                                            OnClientClick='<%# "javascript:window.open(\"" + AppConfiguration.StagedMapPagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" + "\"" + ");" %>'/>
                                </td>

Here's the code generated by asp.net 2.0

                                <td>Map Page</td>
                                <td><input name="ctl00$ContentPlaceHolder1$dlstGeneral$ctl01$txtMapPage" type="text" value="37" readonly="readonly" id="ctl00_ContentPlaceHolder1_dlstGeneral_ctl01_txtMapPage" style="width:50px;" />
                                &nbsp;&nbsp;<input type="submit" name="ctl00$ContentPlaceHolder1$dlstGeneral$ctl01$btnViewMapPage" value="View" onclick="javascript:window.open(&quot;c:\Temp\Staged\1_37.tif&quot;);" id="ctl00_ContentPlaceHolder1_dlstGeneral_ctl01_btnViewMapPage" />
                                </td>

The file c:\Temp\Staged\1_37.tif definitely exists.

When does the OnClientClick event actually fire in the page life cycle?
rmkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

existenz2Commented:
onclick="javascript:window.open(&quot;c:\Temp\Staged\1_37.tif&quot;);" wil not work because of the &quot;.

Problem is here:
OnClientClick='<%# "javascript:window.open(\"" + AppConfiguration.StagedMapPagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" + "\"" + ");" %>'/>

Change it to:
OnClientClick="<%# "javascript:window.open('" + AppConfiguration.StagedMapPagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" + "');" %>"/>
rmkAuthor Commented:
When I try your suggestion I get "server tag is not well formed". These " and ' are driving me nuts.
existenz2Commented:
OnClientClick="javascript:window.open(' <%# AppConfiguration.StagedMapPagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" %> ');" />

looks a bit better I think, should work also.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

rmkAuthor Commented:
I still get the same error
rmkAuthor Commented:
Okay, so now i've used a wrapper function to get the single quotes

                                            OnClientClick='<%# "javascript:window.open(" + Utilities.WrapWithSingleQuote(AppConfiguration.StagedMapPagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif")  + ");" %>'/>

and asp.net 2.0 generates

                                <td>Map Page</td>
                                <td><input name="ctl00$ContentPlaceHolder1$dlstGeneral$ctl01$txtMapPage" type="text" value="37" readonly="readonly" id="ctl00_ContentPlaceHolder1_dlstGeneral_ctl01_txtMapPage" style="width:50px;" />
                                &nbsp;&nbsp;<input type="submit" name="ctl00$ContentPlaceHolder1$dlstGeneral$ctl01$btnViewMapPage" value="View" onclick="javascript:window.open('C:\Temp\Staged\1_37.tif');" id="ctl00_ContentPlaceHolder1_dlstGeneral_ctl01_btnViewMapPage" />
                                </td>

but the OnClinetClick event still won't fire. Do I have to do something special because the file is not in a wwwroot folder?
existenz2Commented:
Is it placed between <form> tags?
rmkAuthor Commented:
Yes. If I change my path for C:\Temp\Staged to //localhost/cats/images/staged then the onclientclick event works. However that causes some other security issues.

To put the whole thing in perspective this is what I'm trying to do:

- from the datalist control I can manufacture the fully qualified name of a file on a network server; at that time I can also manufacture fully qualified name that this file will be copied to on the web server
- in the click event of the btnViewMapPage button which is in the datalist control, I use impersonation to access the file as follows:

        IntPtr token = IntPtr.Zero;
        WindowsImpersonationContext impersonatedUser = null;

        try
        {
            // Create a token for DomainName\Bob
            // Note: Credentials should be encrypted in configuration file
            bool result = LogonUser(AppConfiguration.FileSstemUser,
                                    AppConfiguration.FileSstemDomain,
                                    AppConfiguration.FileSstemPassword,
                                    LogonSessionType.Network,
                                    LogonProvider.Default,
                                    out token);
            if (result)
            {
                WindowsIdentity id = new WindowsIdentity(token);
                etc copy the file to the web server

- still using impersonation, I copy the file from the network server to c:\Temp\Staged\ on the web server. As far as I know I can't copy it to a folder under the web application because the windows account that I am using for impersonation has no privileges for inetpub\wwwroot\...

- finally the OnClientClick event of the btnViewMapPage is supposed to open a new window and show the file that was just copied to the web server. It now seems that the IUSR account that runs the web application does not have privileges to the c:\Temp\Staged folder.

That leaves me with 2 questions:

1) what can I use for a quick fix to demo this thing to my client on Monday morning
2) what is the best practices design for this situation
existenz2Commented:
1) Easy ;) Include the tifs in your project and remove "AppConfiguration.StagedMapPagePath" from the path.
2) I would do it the way you are doing.

But your problem seems to be caused by security.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rmkAuthor Commented:
existenz2 - Thanks for all you help. I managed to get thru my demo just fine and I'll be accepting your answer in a few minutes. If you have the time I would appreciate your comments or suggested links for best practices for my scenario, i.e.

- the wep app needs to copy a file from a network server to a staging area and then view that file form the staging area
- where should that staging area be: a folder under the web app, some other folder on the web server, or what
- should the IUSR account ever be given privileges beyond its default privileges
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.