Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HyperLinkColumn and javascript

Posted on 2004-11-02
12
Medium Priority
?
359 Views
Last Modified: 2008-02-01
Hello..

I have the following setup:

<asp:HyperLinkColumn Text="Update" DataNavigateUrlField="id" DataNavigateUrlFormatString="javascript:updateWin({0})" HeaderText="Update" Visible="False"></asp:HyperLinkColumn>

as a datagrid column

and javascript as:

function updateWin(intId){
   var objEvent = window.event.srcElement;
   alert(objEvent.outerHTML);
}

For some reason, the event is null.. why is this?.. and is there a work around. I want to capture the event and then color the background of the cell thats clicked. Any ideas.. all help appreciated. Thanks
0
Comment
Question by:bLUE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 4

Expert Comment

by:sgalzin
ID: 12473331
hi,

could you please post the resulting html code ? i think i might be able to help you with that.

thanks,

stephane.
0
 
LVL 1

Author Comment

by:bLUE
ID: 12473387
<td><a href="javascript:updateWin(3989)">Update</a></td>
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 12473726
hi,

change the html code to :  <td><a href="javascript:void" onclick="updateWin ( this )">Update</a></td>

and change the js function to this :

function updateWin ( obj ) {
 obj.parentNode.style.backgroundColor = '000000';
}

that should do the trick i think ;-)

hope that helps !

stephane.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:bLUE
ID: 12474125
ahh good idea..

only problem is that obj.parentNode is null..  obj contains some stuff.. ( I did a quick watch on it ). but the parentNode is null..

When i did alert(obj.parentElement.outerHTML); that was empty too ? Any ideas?
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 12474232
hi,

what browser are you using ?

could you please post the outputs of the following alerts ? thanks ! stephane.

function updateWin ( obj ) {
 alert ( obj );
 alert ( obj.innerHTML );
 alert ( obj.outerHTML );
 alert ( obj.parentNode );
 alert ( obj.parentElement );
 alert ( obj.parentNode.style );
 alert ( obj.parentElement.style );
// obj.parentNode.style.backgroundColor = '000000';
}
0
 
LVL 1

Author Comment

by:bLUE
ID: 12474446
alert ( obj );  = [object]
 alert ( obj.innerHTML ); = undefined
 alert ( obj.outerHTML ); = undefined
 alert ( obj.parentNode );= undefined
 alert ( obj.parentElement ); = undefined
 alert ( obj.parentNode.style ); = .net runtime error
 alert ( obj.parentElement.style ); =  .net runtime error


0
 
LVL 4

Expert Comment

by:sgalzin
ID: 12474505
hi again,

are these scripts run from the client (i.e. the browser) ?? could you please repost the resulting html code ? thanks,

stephane.
0
 
LVL 1

Author Comment

by:bLUE
ID: 12474819
The table is actually a asp.net datagrid, and the output is HTML as I pasted earlier.

The scripts above are client code that are contained in the <head>

<HEAD>
<script language="javascript">

function updateWin(intId, obj){
 alert ( obj );
 alert ( obj.innerHTML );
 alert ( obj.outerHTML );
 alert ( obj.parentNode );
 alert ( obj.parentElement );
 alert ( obj.parentNode.style );
 alert ( obj.parentElement.style );

window.open('update.aspx?id='+intId, 'update',"width=600,height=450,scollbars=1");
}
</script>
</head>

<html>
<table....
...<td><a href="javascript:updateWin(3989, this)">Update</a></td>
</table>

Hope this helps..
0
 
LVL 4

Accepted Solution

by:
sgalzin earned 500 total points
ID: 12474878
hi,

i see what's wrong : you haven't changed the html to :
<td><a href="javascript:void" onclick="updateWin ( 3989, this )">Update</a></td>

the code *has to be* in the onclick event, not in the href. it looks like this code is generated automatically though ... can you figure out how to insert the desired html ?
0
 
LVL 1

Author Comment

by:bLUE
ID: 12475384
Ah I see.. The code is generated automatically... but I see how i can add the onclick as an attritube. I will investigate. Thanks
0
 
LVL 1

Author Comment

by:bLUE
ID: 12476096
Got it:

Datagrid column:

<asp:TemplateColumn HeaderText="Update">
 <ItemTemplate>
  <asp:HyperLink id="AttachmentLink" runat="server">Update</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

Item binding code:
private void dgResults_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                  if( (e.Item.ItemType == ListItemType.Item) || ( e.Item.ItemType == ListItemType.AlternatingItem))
                  {
                        HyperLink oLAttachment = (HyperLink)e.Item.FindControl("AttachmentLink");
                        if (oLAttachment != null)
                        {      
                              DbDataRecord objRow = (DbDataRecord)e.Item.DataItem;
                              String strId = objRow["id"].ToString();
                              oLAttachment.Attributes.Add("onClick","updateWin('" + strId + "',this)");
                        }
                  }
            }

jscript:
function updateWin(intId, obj){
                  obj.parentNode.style.backgroundColor = '000000';
                  window.open('update.aspx?id='+intId, 'update',"width=600,height=450,scollbars=1");
            }


:)

Thanks

0
 
LVL 4

Expert Comment

by:sgalzin
ID: 12478506
hi,

sorry i was away for some time ! i'm glad you figured it out (it sounds like i wasn't of much use on the asp part ;-))

cheers,

stephane.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question