如何获取asp.net中动态创建的大量控件的状态
我是asp.net中的一个更环保的人,正在尝试实现一个用例,该用例描述了最近在线电影预订系统中用户选择和预订座位的过程 现在我创建了大量的座椅控件、基于ImageButton定义的web用户控件和“提交”按钮 这些座椅控制装置似乎工作得很好。当您单击座椅时,座椅内图片所反映的座椅状态可能会发生变化。在“提交”按钮的单击事件中,我尝试用ID收集它们的状态,但这些状态都与数据库中的状态相同,这意味着这些控件的状态没有更改 那么,当我单击“提交”按钮时,我应该做什么来获取这些控件的当前状态呢?任何想法都将不胜感激 Seat.ascx如何获取asp.net中动态创建的大量控件的状态,asp.net,webusercontrol,Asp.net,Webusercontrol,我是asp.net中的一个更环保的人,正在尝试实现一个用例,该用例描述了最近在线电影预订系统中用户选择和预订座位的过程 现在我创建了大量的座椅控件、基于ImageButton定义的web用户控件和“提交”按钮 这些座椅控制装置似乎工作得很好。当您单击座椅时,座椅内图片所反映的座椅状态可能会发生变化。在“提交”按钮的单击事件中,我尝试用ID收集它们的状态,但这些状态都与数据库中的状态相同,这意味着这些控件的状态没有更改 那么,当我单击“提交”按钮时,我应该做什么来获取这些控件的当前状态呢?任何想法
public partial class Seat : System.Web.UI.UserControl
{
private string[] Images = { "~/picture/SeatStatus/Default.png", "~/picture/SeatStatus/Chosen.png", "~/picture/SeatStatus/Unavailable.png" };
public string ImageLoc
{
get
{
return this.SeatControl.ImageUrl;
}
set
{
this.SeatControl.ImageUrl = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if (ImageLoc == Images[0])
{
ImageLoc = Images[1];//switch to chosen state
}
else if (ImageLoc == Images[1] )
{
ImageLoc = Images[0]; //switch to available state
}
else
{
//Can not be chosen
}
}
}
ChooseSeat.aspx
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Table ID="SeatTable" runat="server">
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div>
<asp:Button ID="Button1" runat="server" text="Submit" OnClick="Unnamed_Click" />
</div>
CreateControl
TableRow Row = new TableRow();
Row.ID = "Row" + RowNum.ToString();
for (int i = 0; i < str.Length; i++)
{
TableCell Cell;
//'0' represent available, '1' means the seat has been choosen , '2' //stands for unavailable
if (str[i] == '0' || str[i] == '1' || str[i] == '2')
{
Cell = new TableCell();
ColNum++;
Cell.ID = "Row" + RowNum.ToString() + "Cell" + ColNum.ToString();
Seat seat = (Seat)LoadControl("~/Seat.ascx");
seat.ID = "Seat" + Cell.ID;
seat.ID = string.Format("{0}", i);
seat.ImageLoc = Images[str[i] - '0'];
Cell.Controls.Add(seat);
Row.Cells.Add(Cell);
}
else if (str[i] == '3')//3 means passageway
{
Cell = new TableCell();
Cell.ID = "Label" + "Row" + RowNum.ToString() + "Cell" + ColNum.ToString();
Label label = new Label();
label.ID = "Ocup" + Cell.ID;
Cell.Controls.Add(label);
Row.Cells.Add(Cell);
}
else if (str[i] == '-')//'-' means next row
{
SeatTable.Rows.Add(Row);
Row = new TableRow();
RowNum++;
Row.ID = "Row" + RowNum.ToString();
}
else
{
SeatTable.Rows.Add(Row);
break;
}
}
TableRow行=新建TableRow();
Row.ID=“Row”+RowNum.ToString();
对于(int i=0;i
您可能想发布一些代码来显示问题-听起来您在更改控件状态时没有发回服务器谢谢您的回复!我将这些控件放入UpdatePanel以避免页面翻转,但我不知道当这些控件状态更改或未更改时,它是否会发回服务器。我没有看到任何代码将更改后的状态发送到数据库或获取状态-非常感谢,我收到了。