1.调用方法:
<cc1:TabularMultiView ID="TabularMultiView1" runat="server">
<cc1:TabularView ID="view1" runat="Server" Selectable="true" TabName="商品版本">
<asp:Panel ID="panel1" ScrollBars="Auto" runat="Server">
... 里面是自己加的控件
<asp:TextBox ID="txtMerchId" runat="server" MaxLength="30"></asp:TextBox>
... 里面是自己加的控件
</asp:Panel>
</cc1:TabularView>
</cc1:TabularView ...>
<asp:Panel...>
</asp:Panel>
</cc1:TabularView>
依此推!2.问题:但是加载后在服务器端得不到 txtMerchId ;用 txtMerchId.Text都报错!
3.简要源码:
<cc1:TabularMultiView ID="TabularMultiView1" runat="server">
<cc1:TabularView ID="view1" runat="Server" Selectable="true" TabName="商品版本">
<asp:Panel ID="panel1" ScrollBars="Auto" runat="Server">
... 里面是自己加的控件
<asp:TextBox ID="txtMerchId" runat="server" MaxLength="30"></asp:TextBox>
... 里面是自己加的控件
</asp:Panel>
</cc1:TabularView>
</cc1:TabularView ...>
<asp:Panel...>
</asp:Panel>
</cc1:TabularView>
依此推!2.问题:但是加载后在服务器端得不到 txtMerchId ;用 txtMerchId.Text都报错!
3.简要源码:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;namespace AdvControls
{
[
ParseChildren(true, "TabPages"),
ToolboxData("<{0}:MyTabControl runat=\"server\" Width=\"125px\" Height=\"50px\"></{0}:MyTabControl>"),
PersistChildren(false),
Designer(typeof(MyTabControlDesigner))
]
public class MyTabControl : CompositeControl
{
#region private fields
private MyTabPageCollection _tabPages;
private int _currentDesignTab;
private int _selectedTab;
private string _tabcolor,_pagecolor;
#endregion private fields #region public properties
[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
MergableProperty(false)
]
public MyTabPageCollection TabPages
{
get
{
if (_tabPages == null)
{
_tabPages = new MyTabPageCollection();
}
return _tabPages;
}
} /// <summary>
/// Get or set the design time active tab.
/// </summary>
[Browsable(false),
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public int CurrentDesignTab
{
get { return _currentDesignTab; }
set { _currentDesignTab = value; }
} /// <summary>
/// Get or set the runtime active tab.
/// </summary>
public int SelectedTab
{
get { return _selectedTab; }
set { _selectedTab = value; }
}
#endregion public properties /// <summary>
/// Get or set the back color of the tab
/// </summary>
public string TabBackColor
{
get { return _tabcolor; }
set { _tabcolor = value; }
} /// <summary>
/// Get or set the back color of the pages
/// </summary>
public string PageBackColor
{
get { return _pagecolor; }
set { _pagecolor = value; }
} #region private methods
private void BuildTitles(Table tabControlTable)
{
// Create the titles row
TableRow titlesRow = new TableRow();
titlesRow.HorizontalAlign = HorizontalAlign.Center; int i = 0;
foreach (MyTabPage tabPage in _tabPages)
{
// Create titles cells
TableCell tabTitleCell = new TableCell();
tabTitleCell.Text = tabPage.Title;
tabTitleCell.Width = new Unit("");
tabTitleCell.BorderStyle = BorderStyle.Outset;
tabTitleCell.BorderWidth = new Unit("2");
tabTitleCell.Style["padding"] = "0px 4px 0px 4px";
tabTitleCell.Style["cursor"] = "hand";
tabTitleCell.Wrap = false;
tabTitleCell.Height = new Unit("20");
if (!DesignMode)
{
//Highlight the selected tab title
if (_selectedTab == i)
{
//tabTitleCell.Style["background-color"] = ColorTranslator.ToHtml(Color.DarkGray);
tabTitleCell.Style["background-color"] = _tabcolor;
}
}
tabTitleCell.Attributes.Add("onclick", "ShowTab(this, " + i.ToString() + ")"); titlesRow.Cells.Add(tabTitleCell);
i++;
} //Add additional empty cell
TableCell tc1 = new TableCell();
tc1.Width = new Unit("100%");
tc1.Height = new Unit("20");
titlesRow.Cells.Add(tc1);
titlesRow.Height = new Unit("20");
tabControlTable.Rows.Add(titlesRow);
} private void BuildContentRows(Table tabControlTable)
{
// Create content row(s) if (DesignMode)
{
TableRow contentRow = new TableRow();
TableCell contentCell = BuildContentCell(contentRow);
//modify
contentCell.Style["background-color"] = _pagecolor;
_tabPages[_currentDesignTab].TabBody.InstantiateIn(contentCell);
tabControlTable.Rows.Add(contentRow);
}
else
{
int counter = 0;
foreach (MyTabPage tabPage in _tabPages)
{
TableRow contentRow = new TableRow();
TableCell contentCell = BuildContentCell(contentRow); //modify
//contentCell.Style["background-color"] = ColorTranslator.ToHtml(Color.LightGray);"#ece9d8";
contentCell.Style["background-color"] = _pagecolor; if (tabPage.TabBody != null)
{
tabPage.TabBody.InstantiateIn(contentCell);
} //only the selected tab body should be visible
if (_selectedTab == counter)
{
contentRow.Style["display"] = "block";
}
else
{
contentRow.Style["display"] = "none";
}
contentRow.Cells.Add(contentCell);
tabControlTable.Rows.Add(contentRow); counter++;
}
}
} private TableCell BuildContentCell(TableRow tableRow)
{
TableCell tc = new TableCell();
tc.ColumnSpan = _tabPages.Count + 1;
//tc.BackColor = Color.White;
tc.BorderWidth = new Unit("1");
tc.BorderStyle = BorderStyle.Ridge;
//tc.BorderColor = Color.Silver;
tc.Style["padding"] = "5px 5px 5px 5px";
tc.Height = new Unit("100%"); tableRow.Cells.Add(tc); return tc;
}
#endregion private methods #region implementations
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (DesignMode)
{
_tabPages[_currentDesignTab].TabBody.InstantiateIn(this);
}
} protected override void CreateChildControls()
{
// Always start with a clean form
Controls.Clear(); // Create a table using the control's declarative properties
Table tabControlTable = new Table();
tabControlTable.CellSpacing = 1;
tabControlTable.CellPadding = 0;
tabControlTable.BorderStyle = BorderStyle;
tabControlTable.Width = this.Width;
tabControlTable.Height = this.Height;
//tabControlTable.BackColor = ColorTranslator.FromHtml("inactiveborder");
tabControlTable.BackColor = "#ece9d8";//?? //keep a the selected tab index in a an attribute
tabControlTable.Attributes.Add("ActiveTabIdx", _selectedTab.ToString()); BuildTitles(tabControlTable); BuildContentRows(tabControlTable); // Add the finished tabControlTable to the Controls collection
Controls.Add(tabControlTable);
} #endregion implementations
}
}