Annoyingly simple problem

Discussion in 'ASP .Net Datagrid Control' started by Mike Chamberlain, Mar 18, 2005.

  1. Hi.

    Could someone help me with this simple problem?

    I'm trying to open a new window from a HyperLink column in my datagrid.
    The definition of the column is as follows:
    <asp:HyperLinkColumn Text="..."
    DataNavigateUrlField="master_id_account"
    DataNavigateUrlFormatString="javascript:NewBareWindow('/Accounts/Edit.aspx?masterIdAccount={0}',
    'Account{0}', 750, 550);">
    </asp:HyperLinkColumn>

    And this emits the following HTML:

    <td>
    <a
    href="javascript:NewBareWindow('/Accounts/Edit.aspx?masterIdAccount=1211482',
    'Account1211482', 750, 550);">...</a>
    </td>

    I have a javascript function NewBareWindow() that wraps the javascript
    window.open() function. The above works fine except for one small
    problem. The new window opens as expected, but the URL of the original
    window also changes, the page displaying just the word "false",
    presumably because my NewBareWindow function returns false. If I make
    the function return nothing, then [object] is displayed instead of false.

    How do I stop the original page changing when the link is clicked? I'm
    trying to do this only using the VS.NET Datagrid property builder.
    Also, as an experienced web developper, I'm sure I have managed to do
    this correctly countless times before, but I can't seem to get it to
    work here!

    Mike
    Mike Chamberlain, Mar 18, 2005
    #1
    1. Advertising

  2. Hi Mike,

    I think you'll have the problem you are seeing until you move your
    JavaScript to the onclick event and take it off the href attribute. At least
    that's what I noticed the other day.

    Let us know?

    Ken

    "Mike Chamberlain" <> wrote in message
    news:...
    > Hi.
    >
    > Could someone help me with this simple problem?
    >
    > I'm trying to open a new window from a HyperLink column in my datagrid.
    > The definition of the column is as follows:
    > <asp:HyperLinkColumn Text="..."
    > DataNavigateUrlField="master_id_account"
    > DataNavigateUrlFormatString="javascript:NewBareWindow('/Accounts/Edit.aspx?masterIdAccount={0}',
    > 'Account{0}', 750, 550);">
    > </asp:HyperLinkColumn>
    >
    > And this emits the following HTML:
    >
    > <td>
    > <a
    > href="javascript:NewBareWindow('/Accounts/Edit.aspx?masterIdAccount=1211482',
    > 'Account1211482', 750, 550);">...</a>
    > </td>
    >
    > I have a javascript function NewBareWindow() that wraps the javascript
    > window.open() function. The above works fine except for one small
    > problem. The new window opens as expected, but the URL of the original
    > window also changes, the page displaying just the word "false", presumably
    > because my NewBareWindow function returns false. If I make the function
    > return nothing, then [object] is displayed instead of false.
    >
    > How do I stop the original page changing when the link is clicked? I'm
    > trying to do this only using the VS.NET Datagrid property builder. Also,
    > as an experienced web developper, I'm sure I have managed to do this
    > correctly countless times before, but I can't seem to get it to work here!
    >
    > Mike
    Ken Cox [Microsoft MVP], Mar 18, 2005
    #2
    1. Advertising

  3. Hi Ken,

    Indeed that is the case, but unfortunately I don't think that the
    HyperLink column supports the onclick attribute. I was trying to avoid
    having to write any more code.

    Mike

    Ken Cox [Microsoft MVP] wrote:
    > Hi Mike,
    >
    > I think you'll have the problem you are seeing until you move your
    > JavaScript to the onclick event and take it off the href attribute. At
    > least that's what I noticed the other day.
    >
    > Let us know?
    >
    > Ken
    >
    > "Mike Chamberlain" <> wrote in message
    > news:...
    >
    >> Hi.
    >>
    >> Could someone help me with this simple problem?
    >>
    >> I'm trying to open a new window from a HyperLink column in my
    >> datagrid. The definition of the column is as follows:
    >> <asp:HyperLinkColumn Text="..."
    >> DataNavigateUrlField="master_id_account"
    >> DataNavigateUrlFormatString="javascript:NewBareWindow('/Accounts/Edit.aspx?masterIdAccount={0}',
    >> 'Account{0}', 750, 550);">
    >> </asp:HyperLinkColumn>
    >>
    >> And this emits the following HTML:
    >>
    >> <td>
    >> <a
    >> href="javascript:NewBareWindow('/Accounts/Edit.aspx?masterIdAccount=1211482',
    >> 'Account1211482', 750, 550);">...</a>
    >> </td>
    >>
    >> I have a javascript function NewBareWindow() that wraps the javascript
    >> window.open() function. The above works fine except for one small
    >> problem. The new window opens as expected, but the URL of the
    >> original window also changes, the page displaying just the word
    >> "false", presumably because my NewBareWindow function returns false.
    >> If I make the function return nothing, then [object] is displayed
    >> instead of false.
    >>
    >> How do I stop the original page changing when the link is clicked?
    >> I'm trying to do this only using the VS.NET Datagrid property builder.
    >> Also, as an experienced web developper, I'm sure I have managed to do
    >> this correctly countless times before, but I can't seem to get it to
    >> work here!
    >>
    >> Mike

    >
    >
    Mike Chamberlain, Mar 20, 2005
    #3
  4. Hi Mike,

    Were you able to make it work that way?

    Ken


    "Mike Chamberlain" <> wrote in message
    news:...
    > Hi Ken,
    >
    > Indeed that is the case, but unfortunately I don't think that the
    > HyperLink column supports the onclick attribute. I was trying to avoid
    > having to write any more code.
    >
    > Mike
    Ken Cox [Microsoft MVP], Mar 20, 2005
    #4
  5. Yes, after much coercion:
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:HyperLink Runat="server" href="javascript:void(0);"
    onclick='<%# MakeOpenAccountWindowJS(DataBinder.Eval(Container.DataItem,
    "master_id_account")) %>'>...</asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateColumn>

    It took me ages to work out that the onclick needs to be in SINGLE
    quotes. Thanks for your help.

    Mike



    Ken Cox [Microsoft MVP] wrote:
    > Hi Mike,
    >
    > Were you able to make it work that way?
    >
    > Ken
    >
    >
    > "Mike Chamberlain" <> wrote in message
    > news:...
    >
    >> Hi Ken,
    >>
    >> Indeed that is the case, but unfortunately I don't think that the
    >> HyperLink column supports the onclick attribute. I was trying to
    >> avoid having to write any more code.
    >>
    >> Mike

    >
    >
    Mike Chamberlain, Mar 21, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    545
  2. Kevin Spencer

    Re: Simple Simple question!!!

    Kevin Spencer, Jun 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    649
    Kevin Spencer
    Jun 25, 2004
  3. Dave E
    Replies:
    7
    Views:
    734
    Josh Twist
    Jan 11, 2006
  4. dbuchanan
    Replies:
    1
    Views:
    274
    Charles Wang [MSFT]
    Jun 20, 2008
  5. dillon
    Replies:
    1
    Views:
    170
    higabe
    Nov 17, 2003
Loading...

Share This Page