I need help adding "onclick" event to anchor tag dynamically

P

pbd22

Hi.

I am trying to add an "onclick" 'event to an
anchor tag and this is proving harder than
I imagined.

The anchor HAS NO ID. And, there will be tons of them on the page. So,
I cannot access it via FindControl.

the tag is nested as such:

<td></td><td><a href='#'>clicky</a></td><td></td>

My approach has been to muddle with RowDataBound but it isn't clear to
me how to do this.

Please help.
Thanks.

protected void vGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{


if (e.Row.RowType == DataControlRowType.DataRow)
{

//
e.Row.Cells[1].Controls[0].Attributes.Add("onclick",
"alert(getRowText(this));return false;");

}
}
 
P

pbd22

Your code looks fine. Are you experiencing any problem?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


I am trying to add an "onclick" 'event to an
anchor tag and this is proving harder than
I imagined.
The anchor HAS NO ID. And, there will be tons of them on the page. So,
I cannot access it via FindControl.
the tag is nested as such:
<td></td><td><a href='#'>clicky</a></td><td></td>
My approach has been to muddle with RowDataBound but it isn't clear to
me how to do this.
Please help.
Thanks.
protected void vGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//
e.Row.Cells[1].Controls[0].Attributes.Add("onclick",
"alert(getRowText(this));return false;");

Bruce -

Would you mind showing me how to add runat=server to the anchor tags
created in a ButtonField?

Thanks
 
P

pbd22

Your code looks fine. Are you experiencing any problem?
Hi.
I am trying to add an "onclick" 'event to an
anchor tag and this is proving harder than
I imagined.
The anchor HAS NO ID. And, there will be tons of them on the page. So,
I cannot access it via FindControl.
the tag is nested as such:
<td></td><td><a href='#'>clicky</a></td><td></td>
My approach has been to muddle with RowDataBound but it isn't clear to
me how to do this.
Please help.
Thanks.
protected void vGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//
e.Row.Cells[1].Controls[0].Attributes.Add("onclick",
"alert(getRowText(this));return false;");
}
}

Bruce -

Would you mind showing me how to add runat=server to the anchor tags
created in a ButtonField?

Thanks

I am having the same problem with your suggestion - I don't know how
to access the a tag to change its attributes.
I need to do this dynamically from the server but am a bit lost as to
how this is done. Would you mind illustrating
this?

I really appreciate it.

Thanks.
 
P

pbd22

Your code looks fine. Are you experiencing any problem?
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Hi.
I am trying to add an "onclick" 'event to an
anchor tag and this is proving harder than
I imagined.
The anchor HAS NO ID. And, there will be tons of them on the page. So,
I cannot access it via FindControl.
the tag is nested as such:
<td></td><td><a href='#'>clicky</a></td><td></td>
My approach has been to muddle with RowDataBound but it isn't clear to
me how to do this.
Please help.
Thanks.
protected void vGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//
e.Row.Cells[1].Controls[0].Attributes.Add("onclick",
"alert(getRowText(this));return false;");
}
}
Would you mind showing me how to add runat=server to the anchor tags
created in a ButtonField?

I am having the same problem with your suggestion - I don't know how
to access the a tag to change its attributes.
I need to do this dynamically from the server but am a bit lost as to
how this is done. Would you mind illustrating
this?

I really appreciate it.

Thanks.

no takers?
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top