문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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);

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(); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top