ASP.NET动态ASP表与文本框 - 保存价值在ViewState中 [英] ASP.NET dynamic ASP Table with TextBoxes - Save Values in ViewState
问题描述
我有一个网站的.aspx用ASP表。在隐藏文件code我填补行,细胞和细胞中的表是ASP文本框。
I've a .aspx Site with a ASP Table. In the code behind file I fill the table with rows, cells and in the cells are ASP TextBoxes.
在第一次加载我装满价值的文本框从数据库中。但有人正在编辑的价值,并与创建的按钮提交页面后,有表的programmaticaly创建的行没有访问。
At the first load I Fill the TextBoxes with Values out of a database. But after someone is editing the value and submit the Page with a created button, there are no Access to the programmaticaly created rows of the table.
现在我已经看到了一些帖子,一个动态创建的ASP表过得去回传重置了。
now I have seen some postings that a dynamic created asp table is getting resetted by postback.
现在我有一个问题,我怎样才能得到这是由用户在网站上修改的数值?!
now I have a question, how can I get the values which are changed by users on the site?!
我试图重写与SaveViewState和LoadViewState,但页面加载但经过SaveViewState只叫不,如果有人点击一个按钮?
I tried to override the SaveViewState and LoadViewState, but SaveViewState is only called after the Page was loaded but not if someone is clicking a button?
我要保存用户点击一个按钮后,我可以使用他们在code中的文本框的数据。
I'd like to save the data of the Textboxes that i can use them in the code after the user clicked a button.
我该怎么办?
推荐答案
有3这里钥匙,前$ P $完美地@Alexander pssed。
There are 3 keys here, expressed perfectly by @Alexander.
下面是一个code例如:
Here is a code example:
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<form runat="server">
<asp:PlaceHolder ID="placeHolder1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit"/>
</form>
code背后:
Code Behind:
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : Page
{
private static readonly List<String> _listOfThings = new List<String> { "John", "Mary", "Joe" };
private List<TextBox> _myDynamicTextBoxes;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_myDynamicTextBoxes = new List<TextBox>();
var i = 0;
foreach (var item in _listOfThings)
{
var tbox = new TextBox {ID = "TextBox" + (i++),Text=item};
placeHolder1.Controls.Add(tbox); //make sure you are adding to the appropriate container (which must live in a Form with runat="server")
_myDynamicTextBoxes.Add(tbox);
}
}
protected void Button1_Click(Object sender, EventArgs e)
{
foreach (var tbox in _myDynamicTextBoxes)
{
Response.Write(String.Format("You entered '{0}' in {1}<br/>", tbox.Text, tbox.ID));
}
}
}
这篇关于ASP.NET动态ASP表与文本框 - 保存价值在ViewState中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!