I created a TableCell with the TableCell.Text = "text from database" then i add TableCell control into an empty table during page load. I am trying to retrieve the text in the TableCell after a postback by user how should i do that?

my code:

TableRow tr = new TableRow();
        tbl.Controls.Add(tr);
        TableCell tc = new TableCell();
        tc.Text = "<H1>" + GetAssessmentTitle(questionSetId) + "<H1>";
        tc.Attributes.Add("name","title");
        tc.Attributes.Add("id", "title");
        tr.Controls.Add(tc);

I tried doing this by it only able to retrieve the name attribute of the TableCell which is "title" but what i need is the text of the TableCell.

for (int i = 0; i < r.Form.Keys.Count; i++)
        {
            if (r.Form.Keys[i] == "title")
            {

            }
        }

Any help would be appreciated

Please try this.

TableRow tr = new TableRow();
        TableCell tc = new TableCell();
        tc.Text = "<H1>Hello<H1>";
        tc.Attributes.Add("name", "title");
        tc.Attributes.Add("id", "title");
        tr.Controls.Add(tc);
        Table Tb = new Table();
        Tb.Rows.Add(tr);
        this.Controls.Add(Tb);

<asp:Button runat="server" ID="BtnClick" OnClientClick="alert(document.getElementById('title').innerText);" />

Please write a function and assign it to OnClientClick.
Hope it helps

I am trying to get the text to the server side instead of using the clientside javascript....

This article has been dead for over six months. Start a new discussion instead.