0

Hello there i have written some code in jquery to add new input type elements in aspx page! Now I want to fetch values of these elements via ASP.NET! I know if i want to achieve this i will have to store each values in hidden form elements n then fetching hidden element val in cs file! I am curious if i could get a direct/shortcut way to fetch the values of each dynamically added contols in Asp.Net incase there were dozens of elements which were added dynamically in jquery!

Thanks in advance

0

2 Answers 2

0

Give every element you add to your page a class, say "dynamic". Before postback, update a HiddenField like so:

var hiddenValues = "";
$(".dynamic").each(function(){
   hiddenValues += $(this).val() + ",";
});

$("#hiddenField").val(hiddenValues);

Then access the comma delimited hidden field value in the code behind.

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

1 Comment

Thank you so much Troy. You code showed me the rightt way to achieve what i wanted. Im marking it as the correct answer. Thanks!
0

When you add inputs on the client-side, the server doesn't have an object created to access its POST data like it does with your runat="server" controls. There are a few options:

1) Use a script to set the value of a runat="server" HiddenField before postback.

2) Access Request.Form["YourInputName"].

Comments

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.