页面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApp.test.WebForm3" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<fageManager runat="server"/>
<f:TabStrip ID="TabStrip1" Width="950px" Height="350px" ShowBorder="true" ActiveTabIndex="0"
runat="server">
<Tabs> </Tabs>
</f:TabStrip> <br>
<f:Button runat="server" ID="btn1" Text="获取tab个数"></f:Button>
</form>
</body>
</html> 后台:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Slides;
using FineUI; namespace WebApp.test
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = GetDataTable();
FineUI.Tab tab;
for (int i = 0; i < dt.Rows.Count; i++)
{
tab = new FineUI.Tab();
tab.ID = "tab" + dt.Rows[ i]["id"].ToString();
tab.Title = dt.Rows[ i]["name"].ToString(); TabStrip1.Tabs.Add(tab);
} Alert.Show(TabStrip1.Tabs.Count.ToString());
//TabStrip1.ActiveTabIndex = 0;
}
} private DataTable GetDataTable()
{
DataTable dt = new DataTable("table_temp"); dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("age", typeof(int)); DataRow dr = dt.NewRow();
dr["id"] = 1;
dr["name"] = "刘德华";
dr["age"] = 19;
dt.Rows.Add(dr); DataRow dr2 = dt.NewRow();
dr2["id"] = 2;
dr2["name"] = "张惠妹";
dr2["age"] = 20;
dt.Rows.Add(dr2); return dt;
} protected void btn1_OnClick(object sender, EventArgs e)
{
Alert.Show(TabStrip1.Tabs.Count.ToString());
}
}
} ---------------------
如图:为什么!IsPostBack里面可以获取正确的数字,非IsPostBack里获取到的tab的count都是0
|