|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Annoyingly simple problemCould 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 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 Show quoteHide quote "Mike Chamberlain" <n***@hotmail.com> wrote in message news:eti1W53KFHA.3076@tk2msftngp13.phx.gbl... > 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 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: Show quoteHide quote > 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" <n***@hotmail.com> wrote in message > news:eti1W53KFHA.3076@tk2msftngp13.phx.gbl... > >> 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 > > Hi Mike,
Were you able to make it work that way? Ken Show quoteHide quote "Mike Chamberlain" <n***@hotmail.com> wrote in message news:u4mmnRULFHA.2748@TK2MSFTNGP09.phx.gbl... > 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 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: Show quoteHide quote > Hi Mike, > > Were you able to make it work that way? > > Ken > > > "Mike Chamberlain" <n***@hotmail.com> wrote in message > news:u4mmnRULFHA.2748@TK2MSFTNGP09.phx.gbl... > >> 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 > > |
|||||||||||||||||||||||