HyperLinkColumn and javascript

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
LVL 1
bLUEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sgalzinCommented:
hi,

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

thanks,

stephane.
0
bLUEAuthor Commented:
<td><a href="javascript:updateWin(3989)">Update</a></td>
0
sgalzinCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

bLUEAuthor Commented:
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
sgalzinCommented:
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
bLUEAuthor Commented:
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
sgalzinCommented:
hi again,

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

stephane.
0
bLUEAuthor Commented:
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
sgalzinCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bLUEAuthor Commented:
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
bLUEAuthor Commented:
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
sgalzinCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.