0

I have a web forms app which has a piece of jquery that generates a set of inputs, sets the names and ID's correctly to the web forms type names and ID's.

Yet when i post the form back to the server, i cannot find any of those controls with FindControl, though i am able find the original control that is part of the form that the other inputs are cloned from.

I have attempted to use FindControl and used a Recursive version of FindControl that i have created, but nothing can be found. Do i have to go down the Request.Form route, or am i missing something?

4

2 回答 2

1

You wont find the controls generated by jQuery on server side as server controls have their ViewState which asp.net uses on post back. You can use a hidden field to assign the values of your dnymically generaterd code to it and get them from this hidden field on server side code. You will need to make hidden field runat="server"

<input type="hidden" id="hdnjQueryGeneratedControls" runat="server" />

OR

<asp:HiddenField id="hdnjQueryGeneratedControls" runat="server" />
于 2013-10-22T10:10:19.567 回答
0

The reason you can't find the control is because you generate them on the client side and not from the server side. using runat=server

you can:

  1. call ajax method to send the data from the imputs to the server

  2. Create the dynamic inputs from your server side, using repeater of listview

于 2013-10-22T10:12:01.660 回答