开发者

Accessing client-side generated table rows through asp.net server-side

开发者 https://www.devze.com 2022-12-21 11:22 出处:网络
The idea is that a pure html table will 开发者_开发知识库be generated on the client side. (using jQuery to add dynamic new rows to the table when the user clicks a button).

The idea is that a pure html table will 开发者_开发知识库be generated on the client side. (using jQuery to add dynamic new rows to the table when the user clicks a button). These rows contain textboxes, dropdownlists, checkboxes and other input controls.

When the user clicks a button, a PostBack is triggered in which I need to access this data from the table on server side, validate it and perform other actions on it.

I'm able to perform the client side and access the table data on server side by adding runat="server" to the table tag. However, I only see the initial table rows (not the ones added through JavaScript) and I have troubles retrieving the different inputs from the rows.

Can anyone help me out here or put me in the right direction?? Or someone offering a better solution to the problem?

Thanks


Try this:

<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</form>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#Button1").before("<input name='Input1' type='text' />");
    });
</script>

protected void Button1_Click(object sender, EventArgs e)
{
    string input1 = Request["Input1"];
}


Im not in front of my dev computer right now but here are my initial thoughts:

You might try using a datagrid to get your table the way you like it. You can then add and manipulate table rows while you're messing with your server side datasource. That would probably be the best solution to what you're trying to do. I would only use jQuery for this if you're using a different language like PHP.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号