Re: Problem with asp:hyperlink
- From: "Dave Sexton" <dave@jwa[remove.this]online.com>
- Date: Tue, 28 Nov 2006 10:22:58 -0500
Hi Ashish,
The reason it doesn't work is because the string being bound contains
apostrophes, so ASP.NET thinks that your string is ending earlier than it
should when it's being parsed. Complex javascript like that should be
extracted into a script:
<script type="text/javascript">
function showNewWindow(pk)
{
window.open("NewWin.aspx?PK=" + pk, "",
"toolbar=0,width=600,height=600,scollbars=1");
}
</script>
And in the template use the following code:
<asp:HyperLink ID="lnkNewWin" runat="server" NavigateUrl="#"
Text="Click" onclick="javascript:showNewWindow(this.pk)"
pk='<%# DataBinder.Eval(Container.DataItem, "PK") %>'>
</asp:HyperLink>
I'm taking advantage of DHTML expando by adding a custom attribute: pk.
Be sure to place the entire data-binding expression on one line.
If you're using the 2.0 framework you can use <%# Eval("PK") %> instead of
the entire data-binding expression.
BTW, the acronym IIRC stands for "If I remember correctly"
(The acronym BTW stands for "by the way" :)
--
Dave Sexton
<ashtek@xxxxxxxxx> wrote in message
news:1164703756.125886.313190@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thank you for your help Dave.
I tried the code you have given but I am still seeing the same error -
"server tag not well formed". By the way what is IIRC?
Thanks,
-Ashish
Dave Sexton wrote:
Hi Ashish,
The property binding syntax must encapsulate the entire value of the
property and must be surrounded by apostrophes, not quotes, IIRC. Try
this
instead:
onclick='<%#
string.Format("javascript:window.open('NewWin.aspx?PK={0},'','toolbar=0,"
+
"width=600,height=600,scollbars=1')",
DataBinder.Eval(Container.DataItem, "PK")) %>'
--
Dave Sexton
<ashtek@xxxxxxxxx> wrote in message
news:1164700377.056635.133430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have an <ASP:HYPERLINK> on a datagrid (templatecolumn) and I need to
open a new window with no toolbar and specific height & width onclick
of the link. I also want to pass the PK to this new window.
<ASP:HYPERLINK ID="lnkNewWin" RUNAT="server" NAVIGATEURL="#"
ONCLICK="javascript:window.open('NewWin.aspx?PK=<%#
DataBinder.Eval(Container.DataItem,"PK")%>','','toolbar=0,width=600,height=600,scollbars=1')"
TEXT="Click"></ASP:HYPERLINK>
The above code throws an error "Server tag is not well formed".
I am using ONCLICK because I want to specify toolbar=no and height &
width for the new window.
If I replace this <%# DataBinder.Eval(Container.DataItem,"PK")%>
with a numeric value (say 10) then it works fine.
Anyone knows what is wrong with the syntax?
Thanks,
Ashish
.
- Follow-Ups:
- Re: Problem with asp:hyperlink
- From: ashtek
- Re: Problem with asp:hyperlink
- From: Dave Sexton
- Re: Problem with asp:hyperlink
- Prev by Date: Re: Converting string to double
- Next by Date: Re: File drag and drop with Windows Vista
- Previous by thread: Re: Converting form "{X=12, Y=34}" to a Point
- Next by thread: Re: Problem with asp:hyperlink
- Index(es):
Relevant Pages
|