[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2097
  • Last Modified:

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?
0
rmk
Asked:
rmk
  • 5
  • 4
1 Solution
 
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" + "');" %>"/>
0
 
rmkAuthor Commented:
When I try your suggestion I get "server tag is not well formed". These " and ' are driving me nuts.
0
 
existenz2Commented:
OnClientClick="javascript:window.open(' <%# AppConfiguration.StagedMapPagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" %> ');" />

looks a bit better I think, should work also.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rmkAuthor Commented:
I still get the same error
0
 
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?
0
 
existenz2Commented:
Is it placed between <form> tags?
0
 
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
0
 
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.
0
 
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now