Annoyingly simple problem

M

Mike Chamberlain

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
 
K

Ken Cox [Microsoft MVP]

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
 
M

Mike Chamberlain

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
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

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
 
M

Mike Chamberlain

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top