如何使用提交输入控件将.aspx页面的HTML控件值提交到服务器? [英] how to submit HTML controls values from .aspx page to sever using submit input control?

查看:75
本文介绍了如何使用提交输入控件将.aspx页面的HTML控件值提交到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



在我的(.aspx)内容页面上,我使用JQUERY动态创建了一些HTML控件。



这些控件用于从用户收集数据,并将其提交给服务器。



如何使用HTML提交按钮提交值,同一页面的服务器端?



换句话说:



1- HTML控件打开( myPage.aspx)页面

2- HTML提交按钮,而不是ASP.NET按钮

3-在(myPage.aspx.cs)代码中接收提交的数据





 <   asp:内容    ID   =  Content2    ContentPlaceHolderID   =  MainContent    runat   =  服务器 >  

< 输入 id = 名称 type = text value = misha / >

< 输入 id = save type = 提交 value = submit / >

< / asp:内容 >





谢谢

解决方案

您需要将控件置于< ; form> 元素。它需要具有属性 action ,其中包含用于发布HTTP请求的URL的值。如果要提交数据,属性方法应为 method =post



在提交按钮(输入元素的类型提交)上,数据将根据控件的值发送;数据以键值对的形式发送,控件的 name 属性将用作键。



请参阅:

http://www.w3schools.com/tags/tag_form.asp [ ^ ],

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods [ ^ ]。







您的输入元素中的代码示例不显示任何属性 name =name

它们根本没有任何名称属性,但浏览器只使用名称属性作为HTTP请求中的密钥。每个元素中应该有一些唯一值(每个表单): name =name name =address name =telephone



-SA

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


<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

解决方案

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


这篇关于如何使用提交输入控件将.aspx页面的HTML控件值提交到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆