Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
dear all,

On my (.aspx) content page , i have created some HTML controls dynamically using JQUERY.

these controls are used to collect data from user, and submit it to server.

how to submit values using an HTML submit button, to server side of the same page?

in other words :

1- HTML controls are on ( myPage.aspx ) page
2- HTML submit button, not ASP.NET button
3- receive submitted data in ( myPage.aspx.cs ) code


XML
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">

 <input id="name" type="text" value="misha"  />

  <input id="save" type="submit" value="submit" />

</asp:Content>


thanks
Posted
Updated 14-Jan-15 22:22pm
v2

1 solution

You need to put your controls under the <form> element. It needs to have the attribute action with the value of your URL used to post HTTP request. If you want to submit data, the attribute method should be method="post".

On submit button (input element's type "submit") the data will be sent according to the values of the controls; the data is sent in key-value pairs, and the name attributes of controls will be used as keys.

Please see:
http://www.w3schools.com/tags/tag_form.asp[^],
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods[^].

[EDIT]

Your code sample, in input elements, does not show any attributes name="name".
They don't have any name attributes at all, but only name attributes are used by the browsers as key in HTTP request. You should have some unique values (per form) in each element: name="name", name="address", name="telephone", etc.

—SA
 
Share this answer
 
v2
Comments
nina4ever 15-Jan-15 4:40am    
thank you.. but :

1- master page already have a form tag, and i set the method to "Post", so my controls ARE created within the form element already.
2- i added a break point in page_load of (myPage.aspx.cs). when i click submit button, the page is posted back, i.e. form is submitted to server, and page_load of (myPage.aspx.cs) is triggered.
3- i tried to get value of the text field :
string s = "";
if(Page.IsPostBack)
s = Request.Form["name"];
but got an empty string.. THIS IS MY PROBLEM
Sergey Alexandrovich Kryukov 15-Jan-15 11:49am    
You should have mentioned about all those "already have" to free me from redundant explanations before I posted the answer, not after.
Now, your code sample, in input elements, does not show any attributes name="name".
They don't have any name attributes at all, but only name attributes are used by the browsers as key in HTTP request. You should have some unique values (per form) in each element: name="name", name="address", name="telephone", etc.
—SA
nina4ever 18-Jan-15 3:04am    
thank you soooo much. it worked.
and sorry for not mentioning details from the beginning.
would you like to post your reply as a solution so that i can accept it as an answer?
Sergey Alexandrovich Kryukov 18-Jan-15 8:03am    
One solution would be enough to accept, right?
Done, please see the update above, after [EDIT].
—SA
nina4ever 18-Jan-15 4:09am    
another question, please:

i have a group of radio buttons with the same name. when i check one of them, and submit the form, i successfully get the correct checked radio value on server side.
BUT, if no radio is checked on the form, then when submitted, i can't find the group name among AllKeys list in Request.Form..
and i need to get all input values, even if null. is there some way?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900