473,396 Members | 1,693 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,396 software developers and data experts.

how to get the text in JS of a cell created on server?

Bob
Hi,

I have already posted a similar problem but it 's still a problem for me, so
...

I define a table in aspx file and Javascript code.
Purpose: when the user clicks on any cell of the table, the text of it must
be rendered in an Alert.

<asp:Table ID="table1" runat="server">
</asp:Table>

<script language="javascript" type="text/javascript">
function tableclick(event)
{
strid=window.event.srcElement.id
alert(strid) // this works: i get e.g. 3:2
strid=window.event.srcElement.text}
alert(strid) // this doens't work ("undefined")
}

I create row and cells in the code-behind:
Dim r As TableRow
Dim c(50, 20) As TableCell
For i = 0 To 50
r = New TableRow()
For j = 0 To 20
c(i, j) = New TableCell()
c(i, j).ID = j & ":" & i.ToString
r.Cells.Add(c(i, j))
Next
Table1.Rows.Add(r)
Next

c(3, 2).Text = "this is the text i want in Javascript"
....

My problem is that the Alert gives "undefined".
I can get the 'ID' of each cell, why not the 'text'?
I know there is the property 'ClientID' but it's overruled by the ID i
defined in the code, so that's not the point (i think).

Thanks for help.
Bob

Jun 16 '06 #1
4 1492
No, there isn't necessarily.

Code behind is just an object with some properties that are intuitive. In
the end, that in memory object will be turned into a bunch of HTML streamed
down to the browser. So there is not necessarily a correspondance between
the javascript and .NET properties.

Example, the button class has a Text property. But, when that is streamed
down, it is streamed down as an INPUT element, which has a value HTML
property.

I am guesing that this event is not firing on the element you think it is
firing on. You should find out which element it is, and what type it is, to
see what properties or methods it has available.

"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
I tried with innerText, innerHtml, text .... alwyas the sale 'undefined'.
In the code-behind, i have no choice: after the dot after c(i,j) i only
can
take 'text'.
There must be an equivalence between 'text' in code-behind and a property
in
html, no?
..
"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:um**************@TK2MSFTNGP04.phx.gbl...
Depending on the type of element it is, it may not have a 'text'
property.
Try 'innerText' or 'innerHTML' depending on what you want.

I recommend you use the following reference for DHTML so you know what
you
can do with what objects:

http://msdn.microsoft.com/library/de...asp?frame=true

"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> I have already posted a similar problem but it 's still a problem for me, > so
> ..
>
> I define a table in aspx file and Javascript code.
> Purpose: when the user clicks on any cell of the table, the text of it
> must
> be rendered in an Alert.
>
> <asp:Table ID="table1" runat="server">
> </asp:Table>
>
> <script language="javascript" type="text/javascript">
> function tableclick(event)
> {
> strid=window.event.srcElement.id
> alert(strid) // this works: i get e.g. 3:2
> strid=window.event.srcElement.text}
> alert(strid) // this doens't work
> ("undefined")
> }
>
> I create row and cells in the code-behind:
> Dim r As TableRow
> Dim c(50, 20) As TableCell
> For i = 0 To 50
> r = New TableRow()
> For j = 0 To 20
> c(i, j) = New TableCell()
> c(i, j).ID = j & ":" & i.ToString
> r.Cells.Add(c(i, j))
> Next
> Table1.Rows.Add(r)
> Next
>
> c(3, 2).Text = "this is the text i want in Javascript"
> ...
>
> My problem is that the Alert gives "undefined".
> I can get the 'ID' of each cell, why not the 'text'?
> I know there is the property 'ClientID' but it's overruled by the ID i
> defined in the code, so that's not the point (i think).
>
> Thanks for help.
> Bob
>
>
>
>
>



Jun 16 '06 #2
Bob
I tried with innerText, innerHtml, text .... alwyas the sale 'undefined'.
In the code-behind, i have no choice: after the dot after c(i,j) i only can
take 'text'.
There must be an equivalence between 'text' in code-behind and a property in
html, no?
..
"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:um**************@TK2MSFTNGP04.phx.gbl...
Depending on the type of element it is, it may not have a 'text' property.
Try 'innerText' or 'innerHTML' depending on what you want.

I recommend you use the following reference for DHTML so you know what you
can do with what objects:
http://msdn.microsoft.com/library/de...asp?frame=true
"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
Hi,

I have already posted a similar problem but it 's still a problem for me, so
..

I define a table in aspx file and Javascript code.
Purpose: when the user clicks on any cell of the table, the text of it
must
be rendered in an Alert.

<asp:Table ID="table1" runat="server">
</asp:Table>

<script language="javascript" type="text/javascript">
function tableclick(event)
{
strid=window.event.srcElement.id
alert(strid) // this works: i get e.g. 3:2
strid=window.event.srcElement.text}
alert(strid) // this doens't work ("undefined")
}

I create row and cells in the code-behind:
Dim r As TableRow
Dim c(50, 20) As TableCell
For i = 0 To 50
r = New TableRow()
For j = 0 To 20
c(i, j) = New TableCell()
c(i, j).ID = j & ":" & i.ToString
r.Cells.Add(c(i, j))
Next
Table1.Rows.Add(r)
Next

c(3, 2).Text = "this is the text i want in Javascript"
...

My problem is that the Alert gives "undefined".
I can get the 'ID' of each cell, why not the 'text'?
I know there is the property 'ClientID' but it's overruled by the ID i
defined in the code, so that's not the point (i think).

Thanks for help.
Bob



Jun 16 '06 #3
most dom objects have an innerHTML and innerText, be sue you are spelling
them correctly as javascript is case sensitive.

<table>
<tr >
<td onclick="alert(this.innerText)">r1col1</td>
</tr>
</table>

note: window.event is IE only.

-- bruce (sqlwork.com)

"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
I tried with innerText, innerHtml, text .... alwyas the sale 'undefined'.
In the code-behind, i have no choice: after the dot after c(i,j) i only
can
take 'text'.
There must be an equivalence between 'text' in code-behind and a property
in
html, no?
..
"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:um**************@TK2MSFTNGP04.phx.gbl...
Depending on the type of element it is, it may not have a 'text'
property.
Try 'innerText' or 'innerHTML' depending on what you want.

I recommend you use the following reference for DHTML so you know what
you
can do with what objects:

http://msdn.microsoft.com/library/de...asp?frame=true

"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> I have already posted a similar problem but it 's still a problem for me, > so
> ..
>
> I define a table in aspx file and Javascript code.
> Purpose: when the user clicks on any cell of the table, the text of it
> must
> be rendered in an Alert.
>
> <asp:Table ID="table1" runat="server">
> </asp:Table>
>
> <script language="javascript" type="text/javascript">
> function tableclick(event)
> {
> strid=window.event.srcElement.id
> alert(strid) // this works: i get e.g. 3:2
> strid=window.event.srcElement.text}
> alert(strid) // this doens't work
> ("undefined")
> }
>
> I create row and cells in the code-behind:
> Dim r As TableRow
> Dim c(50, 20) As TableCell
> For i = 0 To 50
> r = New TableRow()
> For j = 0 To 20
> c(i, j) = New TableCell()
> c(i, j).ID = j & ":" & i.ToString
> r.Cells.Add(c(i, j))
> Next
> Table1.Rows.Add(r)
> Next
>
> c(3, 2).Text = "this is the text i want in Javascript"
> ...
>
> My problem is that the Alert gives "undefined".
> I can get the 'ID' of each cell, why not the 'text'?
> I know there is the property 'ClientID' but it's overruled by the ID i
> defined in the code, so that's not the point (i think).
>
> Thanks for help.
> Bob
>
>
>
>
>



Jun 16 '06 #4
Bob
Thanks, it works with innerText.
"bruce barker (sqlwork.com)" <b_*************************@sqlwork.com> wrote
in message news:eC**************@TK2MSFTNGP04.phx.gbl...
most dom objects have an innerHTML and innerText, be sue you are spelling
them correctly as javascript is case sensitive.

<table>
<tr >
<td onclick="alert(this.innerText)">r1col1</td>
</tr>
</table>

note: window.event is IE only.

-- bruce (sqlwork.com)

"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
I tried with innerText, innerHtml, text .... alwyas the sale 'undefined'.
In the code-behind, i have no choice: after the dot after c(i,j) i only
can
take 'text'.
There must be an equivalence between 'text' in code-behind and a property
in
html, no?
..
"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:um**************@TK2MSFTNGP04.phx.gbl...
Depending on the type of element it is, it may not have a 'text'
property.
Try 'innerText' or 'innerHTML' depending on what you want.

I recommend you use the following reference for DHTML so you know what
you
can do with what objects:

http://msdn.microsoft.com/library/de...asp?frame=true

"Bob" <sd*@sdvsd.dc> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> I have already posted a similar problem but it 's still a problem for

me,
> so
> ..
>
> I define a table in aspx file and Javascript code.
> Purpose: when the user clicks on any cell of the table, the text of it > must
> be rendered in an Alert.
>
> <asp:Table ID="table1" runat="server">
> </asp:Table>
>
> <script language="javascript" type="text/javascript">
> function tableclick(event)
> {
> strid=window.event.srcElement.id
> alert(strid) // this works: i get e.g. 3:2
> strid=window.event.srcElement.text}
> alert(strid) // this doens't work
> ("undefined")
> }
>
> I create row and cells in the code-behind:
> Dim r As TableRow
> Dim c(50, 20) As TableCell
> For i = 0 To 50
> r = New TableRow()
> For j = 0 To 20
> c(i, j) = New TableCell()
> c(i, j).ID = j & ":" & i.ToString
> r.Cells.Add(c(i, j))
> Next
> Table1.Rows.Add(r)
> Next
>
> c(3, 2).Text = "this is the text i want in Javascript"
> ...
>
> My problem is that the Alert gives "undefined".
> I can get the 'ID' of each cell, why not the 'text'?
> I know there is the property 'ClientID' but it's overruled by the ID i > defined in the code, so that's not the point (i think).
>
> Thanks for help.
> Bob
>
>
>
>
>



Jun 17 '06 #5

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

Similar topics

1
by: johkar | last post by:
I have a grid. When the focus is put on a cell an input is created with the value being the cell's text. I would like to size the input to the physical width of the text. Ideas? John ...
1
by: Dom Nicholas | last post by:
Hi, I have a table (inside a form) that is dynamically created ie the user can add / remove rows dynamically. Each table row has 4 columns : a selection pull down list a text field for...
1
by: Chi | last post by:
Hi There, The following is a popup form that works exactly as I want but I now need to get the values of each text box added when a user clicks the 'Add' button and pass the values back the...
14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
0
by: Michael | last post by:
Hi All, I created a web page from Excel2000, using "Save as web page..."...Publish function. then, I moved htm file to my IIS web server. Then I added a form control, and submit button. How...
3
by: Craig G | last post by:
what way do you code it? i tried the following but it wouldnt display it lblAdd_info is a hidden field in the cell itself that contains the data i want to display in the tooltip text. i added the...
8
by: John Brock | last post by:
I am creating an Excel workbook using VB.NET, and have run into a problem. Excel at times insists on reformatting data that I enter into cells, e.g., converting "01234" to "1234", and this screws...
3
nirmalsingh
by: nirmalsingh | last post by:
i am usinjg ajax technology with c# code behind. i have created html table using c# just like Response.Write("<table>"); .... .... .... Response.Write("</table>"); i want to display text...
2
by: TG | last post by:
Hi! I am trying to export only the visible columns from a datagridview in my windows form in VB 2008. Should't it be no comma after the first row where the headers are? Also should...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
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,...
0
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...
0
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.