Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Using asp:HyperLink to open a new window

Hello,

I am using asp:HyperLink in a c# asp.net application to open a new window in the following way:

<asp:HyperLink ID="lnkSiteName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>'
NavigateUrl='<%# "site.aspx?id=" + DataBinder.Eval (Container.DataItem,"id").ToString()%>' Target="_blank">
</asp:HyperLink>

The window opens just fine with the parameter (id) i have sent.

The only thing i need is to set the window's properties - "toolbar=yes;status=no;location=no;menubar=no;width=280,height=520..."

How can i set those properties?

Thanks,
Dana
0
Relegence
Asked:
Relegence
1 Solution
 
GavinMannionCommented:
To set these properties you need to open the new window with javascript instead.

Basically

<asp:HyperLink ID="lnkSiteName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>'
onclick='javascript:window.open('myWin','<%# "site.aspx?id=" + DataBinder.Eval (Container.DataItem,"id").ToString()%>',"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no"'>
</asp:HyperLink>

Something like that ;)
0
 
meomarCommented:
You can use the Attribuites collections to add theses to the htnl going out to the client

lnkSiteName.Attributes.add("AttributeName", "attribute value");
0
 
David H.H.LeeCommented:
Relegence ,
Add-on solution based on your existing code :
<asp:HyperLink ID="lnkSiteName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>'
NavigateUrl='<%# "site.aspx?id=" + DataBinder.Eval (Container.DataItem,"id").ToString()%>' Target="_blank">
</asp:HyperLink>

Change to
..NavigateUrl="javascript:c=window.open('YOURSOURCE','','toolbar=yes;status=no;location=no;menubar=no;width=280,height=520');c.focus();"...
0
Technology Partners: 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!

 
RelegenceAuthor Commented:
Thanks x com,

When i changed my code i got a parser error - " The server tag is not well formed."

I guess it is because of the ' and " signs... How can i fix that?

This is my code now:
NavigateUrl="javascript:c=window.open('<%# "site.aspx?id=" + DataBinder.Eval (Container.DataItem,"id").ToString()%>','','toolbar=yes;status=no;location=no;menubar=no;width=280,height=520');c.focus();"
0
 
David H.H.LeeCommented:
Relegence ,
Change to this :
<asp:HyperLink Runat=server ID="lnkSiteName"
 NavigateUrl='<%# "javascript:var c= window.open(""site.aspx?id=" & DataBinder.Eval(Container.DataItem,"id") & ""","""",""toolbar=yes;status=no;location=no;menubar=no;width=280,height=520"")" %> ' >Click Me</asp:HyperLink>
                                    
0
 
RelegenceAuthor Commented:

I get a compilation error now - "CS1026: ) expected"

:-(
0
 
David H.H.LeeCommented:
Relegence ,
It work well here. Can you post your code here?
0
 
RelegenceAuthor Commented:
This is my datagrid (which contains 2 hyperlinks columns):

<asp:datagrid id="dgrData" Runat="server" Width="100%" CellPadding="1" BackColor="White" BorderWidth="1px"
BorderColor="#003476" AutoGenerateColumns="False">
<AlternatingItemStyle Font-Size="X-Small" CssClass="rowAlt" HorizontalAlign="Left"></AlternatingItemStyle>
<ItemStyle Font-Size="X-Small" CssClass="row" HorizontalAlign="Left"></ItemStyle>
<HeaderStyle Font-Size="Small" Font-Bold="True" Wrap="False" HorizontalAlign="Center" ForeColor="#F7F7F7"
BackColor="#003476"></HeaderStyle>
<Columns>
    <asp:TemplateColumn HeaderText="" ItemStyle-HorizontalAlign=Center>
        <ItemTemplate>
      <asp:HyperLink ID="lnkViewGroups" runat="server" Text='Groups' NavigateUrl='<%# "groups.aspx?id=" + DataBinder.Eval                             (Container.DataItem,"id").ToString()%>' Target="_blank">
      </asp:HyperLink>
        </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Site Name">
         <ItemTemplate>
      <asp:HyperLink ID="lnkSiteName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' NavigateUrl='<%# "site.aspx?id=" + DataBinder.Eval (Container.DataItem,"id").ToString()%>' Target="_blank">
      </asp:HyperLink>
         </ItemTemplate>
   </asp:TemplateColumn>
   <asp:BoundColumn DataField="description" HeaderText="Description"></asp:BoundColumn>
   <asp:BoundColumn DataField="url" HeaderText="URL"></asp:BoundColumn>
</Columns>
</asp:datagrid>
0
 
David H.H.LeeCommented:
Relegence ,
This line:
<asp:HyperLink ID="lnkViewGroups" runat="server" Text='Groups' NavigateUrl='<%# "groups.aspx?id=" + DataBinder.Eval                             (Container.DataItem,"id").ToString()%>' Target="_blank">

Change to
<asp:HyperLink Runat=server ID="lnkViewGroups" Text='Groups'
 NavigateUrl='<%# "javascript:var c= window.open(""groups.aspx?id=" & DataBinder.Eval(Container.DataItem,"id") & ""","""",""toolbar=yes;status=no;location=no;menubar=no;width=280,height=520"")" %> ' ></asp:HyperLink>

This line:
<asp:HyperLink ID="lnkSiteName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' NavigateUrl='<%# "site.aspx?id=" + DataBinder.Eval (Container.DataItem,"id").ToString()%>' Target="_blank">
     </asp:HyperLink>

Change to:
<asp:HyperLink Runat=server ID="lnkSiteName" Text='<%# DataBinder.Eval(Container.DataItem,"name") %>'
 NavigateUrl='<%# "javascript:var c= window.open(""site.aspx?id=" & DataBinder.Eval(Container.DataItem,"id") & ""","""",""toolbar=yes;status=no;location=no;menubar=no;width=280,height=520"")" %> ' ></asp:HyperLink>

0
 
RelegenceAuthor Commented:
didn't work, i still see:
"Compiler Error Message: CS1026: ) expected"
0
 
David H.H.LeeCommented:
Relegence ,
Can i know your complete error message? I really can't see any problem there because it work well here.
0
 
RelegenceAuthor Commented:
Here it is:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1026: ) expected

Source Error:

 

Line 55:                                                 <asp:TemplateColumn HeaderText="" ItemStyle-HorizontalAlign=Center>
Line 56:                                                       <ItemTemplate>
Line 57:                                                             <asp:HyperLink Runat=server ID="lnkViewGroups" Text='Groups'
Line 58:  NavigateUrl='<%# "javascript:var c= window.open(""groups.aspx?id=" & DataBinder.Eval(Container.DataItem,"id") & ""","""",""toolbar=yes;status=no;location=no;menubar=no;width=280,height=520"")" %> ' ></asp:HyperLink>
Line 59:                                                       </ItemTemplate>
 

Source File: C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx    Line: 57



Show Detailed Compiler Output:


C:\WINNT\system32> "c:\winnt\microsoft.net\framework\v1.1.4322\csc.exe" /t:library /utf8output /R:"c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\mos-kqbt.dll" /R:"c:\winnt\assembly\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3a\system.enterpriseservices.dll" /R:"c:\winnt\assembly\gac\system.data\1.0.5000.0__b77a5c561934e089\system.data.dll" /R:"c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\assembly\dl2\df220b11\d2ed96af_0162c601\relegence.infrastructures.dll" /R:"c:\winnt\assembly\gac\system.web.mobile\1.0.5000.0__b03f5f7f11d50a3a\system.web.mobile.dll" /R:"c:\winnt\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll" /R:"c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll" /R:"c:\winnt\assembly\gac\system.web.services\1.0.5000.0__b03f5f7f11d50a3a\system.web.services.dll" /R:"c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\assembly\dl2\2078c259\5e47adae_0162c601\relegence.utils.dll" /R:"c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll" /R:"c:\winnt\assembly\gac\system.web\1.0.5000.0__b03f5f7f11d50a3a\system.web.dll" /R:"c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll" /R:"c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\assembly\dl2\197a3d07\500b91c9_9267c601\relegence.admintools.wieadmin.dll" /out:"C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\bkr4dbq9.dll" /D:DEBUG /debug+ /optimize- /win32res:"C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\bkr4dbq9.res" /warnaserror /w:1  "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\relegence.admintools.wieadmin\69ed7045\1fdc4f13\bkr4dbq9.0.cs"


Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,90): error CS1026: ) expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,155): error CS1002: ; expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,158): error CS1002: ; expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,160): error CS1002: ; expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,163): error CS1002: ; expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,230): error CS1002: ; expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,233): error CS1002: ; expected
C:\Projects\Development\Relegence.Net\AdminTools\Relegence.AdminTools.WieAdmin\Sites\main.aspx(57,233): error CS1525: Invalid expression term ')'

 
0
 
David H.H.LeeCommented:
Relegence ,
I'm sorry, My existing code is worked for VB.NET. Think it's time for me to sleep.... **sigh**

C# version sure be formatted:
<asp:HyperLink Runat=server ID="lnkViewGroups" Text='Groups' NavigateUrl='<%# "javascript:var c= window.open(\u0027groups.aspx?id=" + DataBinder.Eval(Container.DataItem,"id").ToString() + "\u0027,\u0027newwin\u0027,\u0027toolbar=yes;status=no;location=no;menubar=no;width=280,height=520\u0027)" %> ' >
</asp:HyperLink><br>
0
 
RelegenceAuthor Commented:
It worked.
Thank you sooooo much!!!
0
 
David H.H.LeeCommented:
Welcome.
0

Featured Post

Technology Partners: 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!

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