Re: Problem with asp:hyperlink

Tech-Archive recommends: Fix windows errors by optimizing your registry



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




.



Relevant Pages

  • Returning selected items in an open folder
    ... items in an open folder window. ... Dim boo As Boolean ... '-- s1 is a unique string that's part of a specific open folder path. ... Private Sub Form_QueryUnload ...
    (microsoft.public.vb.general.discussion)
  • Re: Why doesnt this recursive function return the right value?
    ... ByVal WindowTitle As String, _ ... 'finds the first window where the class name start with ClassName ... Dim sWindowTitle As String ...
    (microsoft.public.excel.programming)
  • Re: how to write formatted output <n>f10.5
    ... a format that will do the trick. ... If the character expressions you wanted to print out were, in order, ... leading apostrophe, the string, a trailing aposthrophe, then a comma ... but we want apostrophes... ...
    (comp.lang.fortran)
  • Re: how to write formatted output <n>f10.5
    ... > a format that will do the trick. ... > If the character expressions you wanted to print out were, in order, ... > leading apostrophe, the string, a trailing aposthrophe, then a comma ... > but we want apostrophes... ...
    (comp.lang.fortran)
  • MultiWindowed Adventure Game
    ... - one for the normal game and one for the status window ... wants the statusConsole application to display in the status window. ... so it's important that you pass the actual string ... use the sharedStr type above and initialize ...
    (alt.lang.asm)