473,782 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code behind and onclick on html table row

Hi all,

I have a page with a table of which the rows have to be added dynamically.
What I also want is 'code behind' the onclick event of a row (the page
should be posted back to the server, which should handle the onclick).
However, as the rows are added dynamically, I cannot give them an ID at
designtime and attach a function to it. Is there a way to write one function
for all added rows but that is able to distinguish which of the rows were
clicked? Or is there another way to do this?

TIA,

Corno
Nov 18 '05 #1
2 12242
Corno wrote:
Hi all,

I have a page with a table of which the rows have to be added dynamically.
What I also want is 'code behind' the onclick event of a row (the page
should be posted back to the server, which should handle the onclick).
However, as the rows are added dynamically, I cannot give them an ID at
designtime and attach a function to it. Is there a way to write one function
for all added rows but that is able to distinguish which of the rows were
clicked? Or is there another way to do this?

TIA,

Corno

Allright, let me say this first: I do not suggest this way of working...
(I think) but the following example does work (on 2.0 beta 1).
<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

void Page_Load(objec t sender, EventArgs e)
{
// Declare some table pieces, useful for building tables ;)
Table tbl = new Table();
TableRow tr = new TableRow();
TableCell td0 = new TableCell();
TableCell td1 = new TableCell();
TableCell td2 = new TableCell();

// LinkButton that will cause the actual postback
LinkButton LnkBtn = new LinkButton();
LnkBtn.Click +=new EventHandler(Ln kBtn_Click);
LnkBtn.ID = "HiddenLink ";

// Construct a table with the table elements
td0.Controls.Ad d(LnkBtn);

// just for proper displaying on the client
td0.Style.Add(" display","none" );

// Duhh..
td1.Text = "Foo";
td2.Text = "Bar";

tr.Cells.Add(td 0);
tr.Cells.Add(td 1);
tr.Cells.Add(td 2);

// The trick, add a onclick attribute and you can track the
click as if the LinkButton was clicked.
tr.Attributes.A dd("onclick", "__doPostBack(' " + LnkBtn.ClientID
+ "','')");
//tr.Attributes.A dd("onclick", "__doPostBack(' ','')");
tbl.Rows.Add(tr );

MainPanel.Contr ols.Add(tbl);
}

void LnkBtn_Click(ob ject sender, EventArgs e)
{
// Touchdown!
LabelThatProofs .Text = "Touchdown! ";
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="MainPanel" Runat="server"> </asp:Panel>
<br /><br />
<asp:Label ID="LabelThatPr oofs" Runat="server"> nothing</asp:Label>
</div>
</form>
</body>
</html>

//Rutger
Nov 18 '05 #2
Corno,

You will have to use a client-side "onclick" event. You can pass it a
parameter "this" which will refer to the clicked html table row.

Eliyahu

"Corno" <Corno@dds%FAKE %.nl> wrote in message
news:eK******** ******@TK2MSFTN GP12.phx.gbl...
Hi all,

I have a page with a table of which the rows have to be added dynamically.
What I also want is 'code behind' the onclick event of a row (the page
should be posted back to the server, which should handle the onclick).
However, as the rows are added dynamically, I cannot give them an ID at
designtime and attach a function to it. Is there a way to write one function for all added rows but that is able to distinguish which of the rows were
clicked? Or is there another way to do this?

TIA,

Corno

Nov 18 '05 #3

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

Similar topics

7
1638
by: David. E. Goble | last post by:
Hi all; I have the following files; index.html, sigsheader.js, sigsboby.js, smilesbody.js and smiles.js. The sourse is below. The page displays two manual slide shows... Each slideshow has a set of buttons. the top slideshow (the smiles work fine. How ever the sigs slideshow displays the pictures in the smiles section. *************** index.html ***************************** <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
9
1836
by: David. E. Goble | last post by:
Arrrh! some buttons work while others don't, but I can't see why. I have tried comparing the files that do work, with the ones that don't. But to no help. The funny thing is the parts that work have the same code, except different variables. (Note Javascript and htm code was writen by a c program, the code then run thru a html to js converter)
5
5928
by: Konrad | last post by:
Hi How to write in c# href code so it looks in source Slide - pokaz programu - Remonty firmy Delta Software pls. look source of this link. Thanks
4
5541
by: Carlo Marchesoni | last post by:
I have a button that opens a new Window (some kind of search-window), which is fired using JavaScript (btnSearch.Attributes=".....";) Now I need to run some code behind code BEFORE this JavaScript runs. I tried to define another Button with an EventHandler associated, and from this (after doing my code) fire 'btnSearch.click()'. But I can't make it work. I tried private void Button1_Click(object sender, System.EventArgs e RestartAll()...
5
36880
by: Richard Dixson | last post by:
I created a new C# web application. Basically all I am trying to do is create a table that consists of a few rows with two columns in each. And then to set those columns to text values from my code behind. However I am not able to do this at all, I am going about this wrong, I think and need guideance. If this was just straight HTML I would do this: <table> <tr><td>field 1</td><td>value 1 set by code behind</td></tr>
2
3114
by: Ric | last post by:
im new to asp.net. from what i understand, you have the aspx file (presentation), user-control(ascx file), code-behind(vb file) and components(compiled vb and dll files). the aspx file contains a reference to the ascx which can contain a reference to a component. can an aspx file contain a reference to an ascx file which contains a reference to a code-behind file? ive tried to do this then load the user-control via LoadControl(), but i...
0
1513
by: Edward | last post by:
I'm strictly a high-level programmer, so please excuse my ignorance of the inner magic of ASP etc. I have what my company calls a "builder form". It is used to maintain static lookup lists. It contains a Datagrid control with an Edit Template specified. The code behind contains the following function: Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
1
1851
by: elavarasum | last post by:
Hi, Can any one help me. i have created one color pallet. if i click particular color, it will set as background-color of CardTable. I want to access the particular set in the CardTable from Code behind file. What is the way to access the color. Here is the sample code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
5
2541
by: Mr. X. | last post by:
Hello. In Visual Studio 2008, there is on the toolbox -login -login, which create a login form. On that form there is a LoginButton, which click on it is evented on the "default.aspx.vb" codeBehind. How can I use the value on the codeBehind (default.aspx.vb) of UserName &
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.