How to access HTML control in C# code behind without "runat=server"?

3k views Asked by At

I understand that you can access the server-side HTML control (which has "runat=server") from code behind in C# with FindControl. But my HTML table is a dynamic table, so I can't use it server-sided. How can I get the Rows.Count of this HTML table without "runat=server"? many thanks. UPDATE: After look around, I've encounter some solutions involving postback after assign the value to a hidden field. The point is, the hidden field must be in a physical and seperate html form, while I'm developing a DotNetNuke module control on a ascx file, which inherited the module form. If I add another form, it will says that I can't have 2 forms with runat=server. Still looking for a solution here.

3

There are 3 answers

1
Paolo Tedesco On BEST ANSWER

You can access an HTML control from code behind if it's server side, i.e. if it has the runat="server" attribute.

If your table is filled by some javascript code, you could save the rows number in a form field before the postback.

1
David Hoerster On

If you have access to a javascript framework like jQuery, you could grab the count of table rows and add it to a hidden element that's part of the form you're POSTing like this:

var numberOfRows = $('#yourTableID tr').length;
$('#myHiddenValue').val(numberOfRows);
0
Shrivallabh On

This is what you can use in your code behind if you don't want to use Javascript.

string strValue = Page.Request.Form["name of the textarea HTML control"].ToString();