bLUE
asked on
HyperLinkColumn and javascript
Hello..
I have the following setup:
<asp:HyperLinkColumn Text="Update" DataNavigateUrlField="id" DataNavigateUrlFormatStrin g="javascr ipt:update Win({0})" HeaderText="Update" Visible="False"></asp:Hype rLinkColum n>
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
I have the following setup:
<asp:HyperLinkColumn Text="Update" DataNavigateUrlField="id" DataNavigateUrlFormatStrin
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
ASKER
<td><a href="javascript:updateWin (3989)">Up date</a></ td>
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.backg roundColor = '000000';
}
that should do the trick i think ;-)
hope that helps !
stephane.
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.backg
}
that should do the trick i think ;-)
hope that helps !
stephane.
ASKER
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.ou terHTML); that was empty too ? Any ideas?
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.ou
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.backg roundColor = '000000';
}
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.backg
}
ASKER
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
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
hi again,
are these scripts run from the client (i.e. the browser) ?? could you please repost the resulting html code ? thanks,
stephane.
are these scripts run from the client (i.e. the browser) ?? could you please repost the resulting html code ? thanks,
stephane.
ASKER
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?i d='+intId, 'update',"width=600,height =450,scoll bars=1");
}
</script>
</head>
<html>
<table....
...<td><a href="javascript:updateWin (3989, this)">Update</a></td>
</table>
Hope this helps..
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?i
}
</script>
</head>
<html>
<table....
...<td><a href="javascript:updateWin
</table>
Hope this helps..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah I see.. The code is generated automatically... but I see how i can add the onclick as an attritube. I will investigate. Thanks
ASKER
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(ob ject sender, System.Web.UI.WebControls. DataGridIt emEventArg s e)
{
if( (e.Item.ItemType == ListItemType.Item) || ( e.Item.ItemType == ListItemType.AlternatingIt em))
{
HyperLink oLAttachment = (HyperLink)e.Item.FindCont rol("Attac hmentLink" );
if (oLAttachment != null)
{
DbDataRecord objRow = (DbDataRecord)e.Item.DataI tem;
String strId = objRow["id"].ToString();
oLAttachment.Attributes.Ad d("onClick ","updateW in('" + strId + "',this)");
}
}
}
jscript:
function updateWin(intId, obj){
obj.parentNode.style.backg roundColor = '000000';
window.open('update.aspx?i d='+intId, 'update',"width=600,height =450,scoll bars=1");
}
:)
Thanks
Datagrid column:
<asp:TemplateColumn HeaderText="Update">
<ItemTemplate>
<asp:HyperLink id="AttachmentLink" runat="server">Update</asp
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
Item binding code:
private void dgResults_ItemDataBound(ob
{
if( (e.Item.ItemType == ListItemType.Item) || ( e.Item.ItemType == ListItemType.AlternatingIt
{
HyperLink oLAttachment = (HyperLink)e.Item.FindCont
if (oLAttachment != null)
{
DbDataRecord objRow = (DbDataRecord)e.Item.DataI
String strId = objRow["id"].ToString();
oLAttachment.Attributes.Ad
}
}
}
jscript:
function updateWin(intId, obj){
obj.parentNode.style.backg
window.open('update.aspx?i
}
:)
Thanks
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.
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.
could you please post the resulting html code ? i think i might be able to help you with that.
thanks,
stephane.