如何使用提交输入控件将.aspx页面的HTML控件值提交到服务器?

编程入门 行业动态 更新时间:2024-10-22 23:29:34
本文介绍了如何使用提交输入控件将.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 属性将用作键。 请参阅: www.w3schools/tags/tag_form.asp [ ^ ], en.wikipedia/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: www.w3schools/tags/tag_form.asp[^], en.wikipedia/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控件值提交到服务器?

本文发布于:2023-11-11 18:28:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   如何使用   页面   服务器   aspx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!