📄 tabstrip.cs
字号:
if (target != null)
{
if (_OldMultiPageIndex < 0)
{
SetTargetSelectedIndex();
}
if ((_OldMultiPageIndex >= 0) && (target.SelectedIndex != _OldMultiPageIndex))
{
target.FireSelectedIndexChangeEvent();
}
}
}
/// <summary>
/// Overridden. Creates an EmptyControlCollection to prevent controls from
/// being added to the ControlCollection.
/// </summary>
/// <returns>An EmptyControlCollection object.</returns>
protected override ControlCollection CreateControlCollection()
{
return new EmptyControlCollection(this);
}
/// <summary>
/// Overridden. Verifies certain properties.
/// </summary>
/// <param name="e">An EventArgs object that contains the event data.</param>
protected override void OnInit(EventArgs e)
{
// It may have been possible for a SelectedIndex to be assigned
// before our Items were added. In that case, we cached the
// SelectedIndex, and now we're going to do the assignment.
if (_CachedSelectedIndex != NotSet)
{
SelectedIndex = _CachedSelectedIndex;
_CachedSelectedIndex = NotSet;
}
base.OnInit(e);
}
/// <summary>
/// Overriden. Verifies certain properties.
/// </summary>
/// <param name="e">An EventArgs object that contains the event data.</param>
protected override void OnLoad(EventArgs e)
{
if ((Page != null) && !Page.IsPostBack)
{
if ((TargetID != String.Empty) && (Target == null))
{
// TargetID cannot be found
throw new Exception(GetStringResource("TabStripInvalidTargetID"));
}
foreach (TabItem item in Items)
{
if (item is Tab)
{
Tab tab = (Tab)item;
PageView target = tab.Target;
if ((tab.TargetID != String.Empty) && (target == null))
{
// TargetID cannot be found
throw new Exception(GetStringResource("TabInvalidTargetID"));
}
}
}
SetTargetSelectedIndex();
}
base.OnLoad(e);
}
/// <summary>
/// Overridden. Updates the hidden input's data.
/// </summary>
/// <param name="e">An EventArgs object that contains the event data.</param>
protected override void OnPreRender(EventArgs e)
{
HelperData = SelectedIndex.ToString();
base.OnPreRender(e);
}
/// <summary>
/// Overridden. Renders the TabItems within the Items collection.
/// </summary>
/// <param name="writer">The output stream that renders HTML content to the client.</param>
protected override void RenderContents(HtmlTextWriter writer)
{
foreach (TabItem item in Items)
{
item.Render(writer, RenderPath);
}
}
/// <summary>
/// The rendering path for uplevel browsers.
/// </summary>
/// <param name="writer">The output stream that renders HTML content to the client.</param>
protected override void RenderUpLevelPath(HtmlTextWriter writer)
{
writer.Write("<?XML:NAMESPACE PREFIX=\"" + TagNamespace
+ "\" /><?IMPORT NAMESPACE=\"" + TagNamespace + "\" IMPLEMENTATION=\""
+ AddPathToFilename("tabstrip.htc") + "\" />");
writer.WriteLine();
AddAttributesToRender(writer);
writer.AddAttribute("selectedIndex", SelectedIndex.ToString());
if (Orientation == Orientation.Vertical)
writer.AddAttribute("orientation", "vertical");
if (TargetID != String.Empty)
writer.AddAttribute("targetID", Target.ClientID);
if (SepDefaultImageUrl != String.Empty)
writer.AddAttribute("sepDefaultImageUrl", SepDefaultImageUrl);
if (SepHoverImageUrl != String.Empty)
writer.AddAttribute("sepHoverImageUrl", SepHoverImageUrl);
if (SepSelectedImageUrl != String.Empty)
writer.AddAttribute("sepSelectedImageUrl", SepSelectedImageUrl);
string style = TabDefaultStyle.CssText;
if (style != String.Empty)
writer.AddAttribute("tabDefaultStyle", style);
style = TabHoverStyle.CssText;
if (style != String.Empty)
writer.AddAttribute("tabHoverStyle", style);
style = TabSelectedStyle.CssText;
if (style != String.Empty)
writer.AddAttribute("tabSelectedStyle", style);
style = SepDefaultStyle.CssText;
if (style != String.Empty)
writer.AddAttribute("sepDefaultStyle", style);
style = SepHoverStyle.CssText;
if (style != String.Empty)
writer.AddAttribute("sepHoverStyle", style);
style = SepSelectedStyle.CssText;
if (style != String.Empty)
writer.AddAttribute("sepSelectedStyle", style);
if (Page != null)
{
string script = ClientHelperID + ".value" + "=event.index";
if (AutoPostBack)
{
script += ";if (getAttribute('_submitting') != 'true'){setAttribute('_submitting','true');try{" + Page.GetPostBackEventReference(this, String.Empty) + ";}catch(e){setAttribute('_submitting','false');}}";
}
writer.AddAttribute("onSelectedIndexChange", "JScript:" + script);
writer.AddAttribute("onwcready", "JScript:try{" + ClientHelperID + ".value=selectedIndex}catch(e){}");
}
writer.RenderBeginTag(TagNamespace + ":" + TabStripTagName);
writer.WriteLine();
base.RenderUpLevelPath(writer);
writer.RenderEndTag();
}
/// <summary>
/// The rendering path for downlevel browsers.
/// </summary>
/// <param name="writer">The output stream that renders HTML content to the client.</param>
protected override void RenderDownLevelPath(HtmlTextWriter writer)
{
writer.WriteLine("<script language=\"javascript\">" + ClientHelperID + ".value=" + SelectedIndex.ToString() + ";</script>");
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
AddAttributesToRender(writer);
writer.RenderBeginTag(HtmlTextWriterTag.Table);
if (Orientation == Orientation.Horizontal)
{
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
}
base.RenderDownLevelPath(writer);
if (Orientation == Orientation.Horizontal)
{
writer.RenderEndTag(); // TR
}
writer.RenderEndTag(); // TABLE
}
/// <summary>
/// The rendering path for visual designers.
/// </summary>
/// <param name="writer">The output stream that renders HTML content to the client.</param>
protected override void RenderDesignerPath(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
AddAttributesToRender(writer);
writer.RenderBeginTag(HtmlTextWriterTag.Table);
if (Orientation == Orientation.Horizontal)
{
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
}
base.RenderDesignerPath(writer);
if (Orientation == Orientation.Horizontal)
{
writer.RenderEndTag(); // TR
}
writer.RenderEndTag(); // TABLE
}
/// <summary>
/// Loads the control's previously saved view state.
/// </summary>
/// <param name="savedState">An object that contains the saved view state values for the control.</param>
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] state = (object[])savedState;
base.LoadViewState(state[0]);
((IStateManager)Items).LoadViewState(state[1]);
((IStateManager)TabDefaultStyle).LoadViewState(state[2]);
((IStateManager)TabHoverStyle).LoadViewState(state[3]);
((IStateManager)TabSelectedStyle).LoadViewState(state[4]);
((IStateManager)SepDefaultStyle).LoadViewState(state[5]);
((IStateManager)SepHoverStyle).LoadViewState(state[6]);
((IStateManager)SepSelectedStyle).LoadViewState(state[7]);
}
}
/// <summary>
/// Saves the changes to the control's view state to an Object.
/// </summary>
/// <returns>The object that contains the view state changes.</returns>
protected override object SaveViewState()
{
object[] state = new object[]
{
base.SaveViewState(),
((IStateManager)Items).SaveViewState(),
((IStateManager)TabDefaultStyle).SaveViewState(),
((IStateManager)TabHoverStyle).SaveViewState(),
((IStateManager)TabSelectedStyle).SaveViewState(),
((IStateManager)SepDefaultStyle).SaveViewState(),
((IStateManager)SepHoverStyle).SaveViewState(),
((IStateManager)SepSelectedStyle).SaveViewState(),
};
// Check to see if we're really saving anything
foreach (object obj in state)
{
if (obj != null)
{
return state;
}
}
return null;
}
/// <summary>
/// Instructs the control to track changes to its view state.
/// </summary>
protected override void TrackViewState()
{
base.TrackViewState();
((IStateManager)TabDefaultStyle).TrackViewState();
((IStateManager)TabHoverStyle).TrackViewState();
((IStateManager)TabSelectedStyle).TrackViewState();
((IStateManager)SepDefaultStyle).TrackViewState();
((IStateManager)SepHoverStyle).TrackViewState();
((IStateManager)SepSelectedStyle).TrackViewState();
((IStateManager)Items).TrackViewState();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -