problem of changing values for tableCell element

M

Mr. x

Hello,
I have the following aspx code :

<form id = "main_form" runat = "server">

<asp:Table dir = "rtl" runat = "server">
<asp:TableRow>
<asp:TableCell id = "inner_message">&nbsp;</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>


How can I change the contents of the value of TableCell in the server side
script ?

(What should I write in the following :
<script runat="server">
...
inner_message.innerHtml = "some message" ' doesn't work - what
should I put instead.
</script>
)

Thanks :)
 
M

Mr. x

Patrick Dahmen said:
In your code, the runat=server is missing. may that help ???

Well,
that's what I did - as you see at my code,
so I don't understand what's wrong.
Also, I can access inner_message (so it's not seems as runat=server
mistake).
The question is how can I change it, please.

Thanks :)
 
E

Eric Veltman

Mr. x said:
(What should I write in the following :
<script runat="server">
...
inner_message.innerHtml = "some message" ' doesn't work - what
should I put instead.
</script>

What do you mean with "doesn't work" ?
Do you get an error message and if so, what's the error ?

Does it work if you access the cell by doing it like
table.Rows[0].Cells[0].InnerHtml = "some message" ?

Regards,

Eric
 
K

Ken Cox [Microsoft MVP]

If you need to look for the tablecell according to its ID, here's a way that
will do it. It is much more efficient if you can just reference it by index
(such as tblrow.Cells(0) )

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim tblrow As TableRow
Dim tblcell As TableCell
Table1.GridLines = GridLines.Both
tblrow = Table1.Rows(0)
tblcell = tblrow.Cells _
(tblrow.Controls.IndexOf _
(tblrow.FindControl _
("inner_message")))
tblcell.Text = "Mr. X should use a friendlier name."
End Sub
 
E

Eitan

Ken Cox wrote :
If you need to look for the tablecell according to its ID, here's a way that
will do it. It is much more efficient if you can just reference it by index
(such as tblrow.Cells(0) )

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim tblrow As TableRow
Dim tblcell As TableCell
Table1.GridLines = GridLines.Both
tblrow = Table1.Rows(0)
tblcell = tblrow.Cells _
(tblrow.Controls.IndexOf _
(tblrow.FindControl _
("inner_message")))
tblcell.Text = "Mr. X should use a friendlier name."
End Sub
I have checked this out.
It may be a tinny mistake, but I get the message :
System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values. Parameter name: index

I suppose tblrow.FindControl("inner_message") returns null, or -1,
but there is something in the code which is wrong, which I cannot figure
out.
tblcell.Text = "Mr. X should use a friendlier name."

O.K, I'm Eitan (and from now on, I'll keep using my original name, althogh I
hate spams - I have 2 years my account in the same ISP, and I don't get even
one single spam ... For only the name - it's fine with me, but beleive me I
am getting more response then I used to before I used Mr.X's name).

Thanks :)
 
K

Ken Cox [Microsoft MVP]

Hi Eitan,

Strange, 'cause it works for me in ASP.NET 1.1 . Here's the complete code in
case that helps:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="tbl.aspx.vb"
Inherits="p4320work.tbl"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>tbl</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="main_form" runat="server">
<asp:Table dir="rtl" runat="server" ID="Table1" NAME="Table1">
<asp:TableRow>
<asp:TableCell id="inner_message">&nbsp;</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</HTML>

''''''''

Public Class tbl
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Table1 As System.Web.UI.WebControls.Table

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim tblrow As TableRow
Dim tblcell As TableCell
Table1.GridLines = GridLines.Both
tblrow = Table1.Rows(0)
tblcell = tblrow.Cells _
(tblrow.Controls.IndexOf _
(tblrow.FindControl _
("inner_message")))
tblcell.Text = "Hi Eitan!."
End Sub

End Class
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top