rmk
asked on
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" />
<asp:Button ID="btnViewMapPage" runat="server"
CommandName = "ViewMapPage"
Text="View"
OnClientClick='<%# "javascript:window.open(\" " + AppConfiguration.StagedMap PagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" + "\"" + ");" %>'/>
</td>
Here's the code generated by asp.net 2.0
<td>Map Page</td>
<td><input name="ctl00$ContentPlaceHo lder1$dlst General$ct l01$txtMap Page" type="text" value="37" readonly="readonly" id="ctl00_ContentPlaceHold er1_dlstGe neral_ctl0 1_txtMapPa ge" style="width:50px;" />
<input type="submit" name="ctl00$ContentPlaceHo lder1$dlst General$ct l01$btnVie wMapPage" value="View" onclick="javascript:window .open(&quo t;c:\Temp\ Staged\1_3 7.tif" ;);" id="ctl00_ContentPlaceHold er1_dlstGe neral_ctl0 1_btnViewM apPage" />
</td>
The file c:\Temp\Staged\1_37.tif definitely exists.
When does the OnClientClick event actually fire in the page life cycle?
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" />
<asp:Button ID="btnViewMapPage" runat="server"
CommandName = "ViewMapPage"
Text="View"
OnClientClick='<%# "javascript:window.open(\"
</td>
Here's the code generated by asp.net 2.0
<td>Map Page</td>
<td><input name="ctl00$ContentPlaceHo
<input type="submit" name="ctl00$ContentPlaceHo
</td>
The file c:\Temp\Staged\1_37.tif definitely exists.
When does the OnClientClick event actually fire in the page life cycle?
ASKER
When I try your suggestion I get "server tag is not well formed". These " and ' are driving me nuts.
OnClientClick="javascript: window.ope n(' <%# AppConfiguration.StagedMap PagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif" %> ');" />
looks a bit better I think, should work also.
looks a bit better I think, should work also.
ASKER
I still get the same error
ASKER
Okay, so now i've used a wrapper function to get the single quotes
OnClientClick='<%# "javascript:window.open(" + Utilities.WrapWithSingleQu ote(AppCon figuration .StagedMap PagePath + Eval("StagedMapPageID") + "_" + Eval("MapPage") + ".tif") + ");" %>'/>
and asp.net 2.0 generates
<td>Map Page</td>
<td><input name="ctl00$ContentPlaceHo lder1$dlst General$ct l01$txtMap Page" type="text" value="37" readonly="readonly" id="ctl00_ContentPlaceHold er1_dlstGe neral_ctl0 1_txtMapPa ge" style="width:50px;" />
<input type="submit" name="ctl00$ContentPlaceHo lder1$dlst General$ct l01$btnVie wMapPage" value="View" onclick="javascript:window .open('C:\ Temp\Stage d\1_37.tif ');" id="ctl00_ContentPlaceHold er1_dlstGe neral_ctl0 1_btnViewM apPage" />
</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?
OnClientClick='<%# "javascript:window.open(" + Utilities.WrapWithSingleQu
and asp.net 2.0 generates
<td>Map Page</td>
<td><input name="ctl00$ContentPlaceHo
<input type="submit" name="ctl00$ContentPlaceHo
</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?
Is it placed between <form> tags?
ASKER
Yes. If I change my path for C:\Temp\Staged to //localhost/cats/images/st aged 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;
WindowsImpersonationContex t impersonatedUser = null;
try
{
// Create a token for DomainName\Bob
// Note: Credentials should be encrypted in configuration file
bool result = LogonUser(AppConfiguration .FileSstem User,
AppConfiguration.FileSstem Domain,
AppConfiguration.FileSstem Password,
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
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;
WindowsImpersonationContex
try
{
// Create a token for DomainName\Bob
// Note: Credentials should be encrypted in configuration file
bool result = LogonUser(AppConfiguration
AppConfiguration.FileSstem
AppConfiguration.FileSstem
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
- 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
Problem is here:
OnClientClick='<%# "javascript:window.open(\"
Change it to:
OnClientClick="<%# "javascript:window.open('"