0

I need to add dynamic fields using jQuery, something like this one: http://bit.ly/AByQZb
But the problem is I don't know how to do it with asp.net forms so I can see these new fields in code behind.
I thought I can use a repeater and in code behind on click method of a button I increase or decrease the items count which containing the fields I want, is there a better idea (client side approach) ?

Thanx in advanced

2
  • as asp.net control will be interpreted as html control in browser and if you want to create control dynamically you need to call .clone() method Commented Apr 8, 2012 at 20:32
  • I'm o.k about calling this method, but I can't see the added fields in code behind, this is the main issue here. Commented Apr 8, 2012 at 20:44

1 Answer 1

2

As long as the fields are added inside the <form> tag, and the names and IDs do not conflict with any other elements, they will still be part of the postback data, so you should be able to access the values using the Request.Form collection.

C#:

string dynamicValue = Request.Form["dynamicTextName"].ToString();

VB:

Dim dynamicValue as String = Request.Form("dynamicTextName").ToString()

Since these fields have been dynamically added on the client side, they are by definition not server side controls which normally have the runat="Server" attribute in the markup. So you will not see a corresponding object in your code-behind which allows you to access the various properties.

You can validate that the dynamic values are submitted with the form by using Fiddler, the IE Developer Tools or Firebug.

Sign up to request clarification or add additional context in comments.

5 Comments

I thought about this approach but, wondered if there's javascript code allows me to see corresponding objects in code-behind.
By "seeing" them I assume you mean have an object to reference them with? Like when you drag and drop a button control onto the designer? Those are controls that the server is already aware of, not added dynamically at run time. The only way to "see" them is to add them in the designer.
Well, now that I think about it, you could add the entire row as a UserControl, and add some logic in the UC code behind...
can you please clarify you idea about using UC ?, and yes I meant by "See" what you said.
At this point I think that is a separate question, since yours starts with "I need to add dynamic fields using jQuery". Perhaps you could start a new question with a more open nature about the task you are trying to accomplish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.