473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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;");

}
}

Oct 24 '07 #1
4 7188
Your code looks fine. Are you experiencing any problem?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"pbd22" <du*****@gmail.comwrote in message
news:11**********************@v29g2000prd.googlegr oups.com...
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;");

}
}

Oct 24 '07 #2
On Oct 24, 9:49 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Your code looks fine. Are you experiencing any problem?

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

"pbd22" <dush...@gmail.comwrote in message

news:11**********************@v29g2000prd.googlegr oups.com...
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

Oct 24 '07 #3
On Oct 24, 11:03 am, pbd22 <dush...@gmail.comwrote:
On Oct 24, 9:49 am, "Eliyahu Goldin"

<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Your code looks fine. Are you experiencing any problem?
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"pbd22" <dush...@gmail.comwrote in message
news:11**********************@v29g2000prd.googlegr oups.com...
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.

Oct 24 '07 #4
On Oct 24, 11:13 am, pbd22 <dush...@gmail.comwrote:
On Oct 24, 11:03 am, pbd22 <dush...@gmail.comwrote:
On Oct 24, 9:49 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Your code looks fine. Are you experiencing any problem?
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"pbd22" <dush...@gmail.comwrote in message
>news:11**********************@v29g2000prd.googleg roups.com...
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.
no takers?

Oct 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dipin | last post by:
Hi All; I have this javascript which is adding a new button to the column in the row which is created dynamically, the innerhtml shows that the onclick event is correctly added but it never gets...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
1
by: Hrvoje Vrbanc | last post by:
Hello all! My question is the following: I add buttons (server controls) programatically into a table cell. Example: Dim btObnovi As Button = New Button() celija25.Controls.Add(btObnovi) ...
0
by: Rick | last post by:
I have a panel that I have set up to look like a command button with Text and an image. I would like to have an onclick event that runs code in the code behind page, not on the client. It is...
11
by: Daz | last post by:
Hello everyone. I am sure the answer to my question is simple, but I can't seem to dynamically add an onClick event to my script. I have a table which is generated dynamically, I am just...
3
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick...
0
by: felixch | last post by:
Hi all, I tried to add an OnClick event to a LinkButton by using Attribute.sAdd, which resides in a Repeater and the Repeater is bind with a DataTable with around 2000 records. If I try to run...
1
by: pbd22 | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.