ASP.NET:在codebehind阅读记忆动态生成HTML元素的值 [英] ASP.NET : Reading dynamically generated HTML element value in codebehind

查看:123
本文介绍了ASP.NET:在codebehind阅读记忆动态生成HTML元素的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net页面,我有以下markup.Basically是从codebehind通过从表中读取记录和循环直通them.For表中的每个记录生成该标记,就会有一个div块

I have an asp.net page where i have the below markup.Basically this markup is generated from codebehind by reading records from a table and looping thru them.For each record in table,there will be a div block.

基本上这个形式是一个user.The设置条目存储在一个表中读取/播放设置。

Basically this form is to read/show settings for a user.The settings entries are stored in a table.

<div id='divContainer' runat='server'>

 <div id='div1' runat='server'>
    <table>
      <tr>
        <th>Name</th>
        <td><input type='text' id='txtName1' value='something' /></td>
      </tr>
       </table>
 </div>
 <div id='div2' runat='server'>
    <table>
      <tr>
        <th>Domain name</th>
        <td><input type='text' id='txtName2' value='something' /></td>
      </tr>
     </table>
 </div>
 <div id='div3' runat='server'>
    <table>
      <tr>
        <th>URL</th>
        <td><input type='text' id='txtName3' value='something' /></td>
      </tr>
      </table>
 </div>
 <div id='div4' runat='server'>
    <table>
      <tr>
        <th>Some other value is enabled ?</th>
        <td><input type='checkbox' id='chk4'  /></td>
      </tr>
      </table>
 </div>

</div>

该标识每个输入元素的将是独一无二的。现在,在codebehind我想读每个输入elment的值保存更改用户i made.How可以在这里阅读的元素?由于在codebehind作为一个字符串生成标记和附加外部div的内部HTML,就像我们在IDE中,我们将一个控制和下降做我不能读值。

The id's of each input element will be unique. Now in codebehind i want to read the values of each input elment to save the changes user made.How can i read the elements here ? Since the mark up is generated in codebehind as a string and appended the the INNER HTML of the external div,I cant read values like we do for a control which we drag and drop in the IDE.

有什么想法?在此先感谢

Any thoughts ? Thanks in advance

推荐答案

如果这些被送回页面在一个标准的HTTP POST,那么你可以在 的Request.Form NameValueCollection中

If these are being sent back to the page in a standard HTTP POST then you can read the values in the Request.Form NameValueCollection.

从本质上讲,所有成为表单元素的服务器控件会转换成标准的HTML表单元素,就像你在那里,虽然与.NET生成,以帮助它识别它们更多的标记。然后,它会自动它们的值映射回服务器控件为您在回传,但值本身也只是在一个标准的HTTP POST,您可以手动访问。

Essentially, all of the server controls that become form elements get translated into standard HTML form elements just as you have there, albeit with more markup generated by .NET to help it identify them. Then it automatically maps their values back to the server controls for you on the postback, but the values themselves are still just in a standard HTTP POST, which you can access manually.

(这也可以发布从一个ASP .NET应用到另一种形式时使用的常用的方法。)

(This is also a common method used when posting a form from one ASP .NET application to another.)

这篇关于ASP.NET:在codebehind阅读记忆动态生成HTML元素的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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