📄 navigationnode.cs
字号:
[DefaultValue("")]
public string Target
{
get
{
string o = Properties[GetAttributeVarName("Target")];
return (o == null) ? (navigator == null? string.Empty : navigator.DefaultTarget) : o;
}
set
{
Properties[GetAttributeVarName("Target")] = value;
}
}
/// <summary>
/// Deprecated. Use <see cref="ServerTemplateId"/> instead.
/// </summary>
/// <seealso cref="ServerTemplateId" />
[Browsable(false)]
[Category("Appearance")]
[Description("Deprecated. Use ServerTemplateId instead.")]
[DefaultValue("")]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string TemplateId
{
get
{
return ServerTemplateId;
}
set
{
ServerTemplateId = value;
}
}
/// <summary>
/// Text label of this node.
/// </summary>
[Category("Appearance")]
[Description("Text label of this node.")]
[DefaultValue("")]
public string Text
{
get
{
string o = Properties[GetAttributeVarName("Text")];
return (o == null) ? string.Empty : o;
}
set
{
Properties[GetAttributeVarName("Text")] = value;
}
}
/// <summary>
/// ToolTip to display for this item.
/// </summary>
[Description("ToolTip to display for this item.")]
[DefaultValue("")]
public override string ToolTip
{
get
{
string o = Properties[GetAttributeVarName("ToolTip")];
return (o == null) ? string.Empty : o;
}
set
{
Properties[GetAttributeVarName("ToolTip")] = value;
}
}
/// <summary>
/// Optional internal string value of this node.
/// </summary>
[Description("Optional internal string value of this node.")]
[Category("Data")]
[DefaultValue("")]
public string Value
{
get
{
string o = Properties[GetAttributeVarName("Value")];
return (o == null) ? string.Empty : o;
}
set
{
Properties[GetAttributeVarName("Value")] = value;
}
}
/// <summary>
/// Whether this node should be displayed.
/// </summary>
[Description("Whether this node should be displayed.")]
[Category("Data")]
[DefaultValue(true)]
public override bool Visible
{
get
{
string o = Properties[GetAttributeVarName("Visible")];
return (o == null) ? true : Utils.ParseBool(o, true);
}
set
{
Properties[GetAttributeVarName("Visible")] = value.ToString();
}
}
#endregion
#region Public Methods
public NavigationNode()
{
// If we're not in design-time, use Attributes instead of Properties
if(Context != null)
{
// First, copy Properties to Attributes
foreach(string sKey in Properties.Keys)
{
Attributes[sKey] = Properties[sKey];
}
// Make Properties point to Attributes
Properties = Attributes;
}
}
/// <summary>
/// Get the zero-based index of this NavigationNode within its group. A negative value is
/// returned if the index could not be computed, for example if the node doesn't belong to
/// a group at all.
/// </summary>
/// <returns>The zero-based index of this NavigationNode within its group.</returns>
public int GetCurrentIndex()
{
NavigationNodeCollection arNodes;
if(this.parentNode != null)
{
arNodes = this.parentNode.nodes;
}
else if(this.navigator != null)
{
arNodes = this.navigator.nodes;
}
else
{
return -1;
}
return arNodes.IndexOf(this);
}
/// <summary>
/// Find a control in this node's template instance.
/// </summary>
/// <param name="sID">ID of the sought control</param>
/// <returns>
/// The control with the given ID contained inside the template instance for this node,
/// if the node is templated, or null if it isn't or the control is not found.
/// </returns>
/// <seealso cref="ServerTemplateId" />
public override Control FindControl(string sID)
{
if(this.ServerTemplateId != string.Empty && this.navigator != null)
{
foreach(Control oControl in this.navigator.Controls)
{
if(oControl.ID.EndsWith("_" + this.PostBackID))
{
Control result = oControl.FindControl(sID);
// look inside user control?
if(result == null && oControl.Controls.Count == 1 && oControl.Controls[0] is UserControl)
{
return oControl.Controls[0].FindControl(sID);
}
else
{
return result;
}
}
}
}
return null;
}
/// <summary>
/// IsDescendantOf method.
/// </summary>
/// <param name="oAncestor">Node to check</param>
/// <returns>Whether the given node is an ancestor of this one</returns>
public bool IsDescendantOf(NavigationNode oAncestor)
{
NavigationNode oNode = this.parentNode;
while(oNode != null)
{
if(oNode == oAncestor)
{
return true;
}
oNode = oNode.parentNode;
}
return false;
}
/// <summary>
/// Navigates to the set NavigateUrl for this node.
/// </summary>
/// <remarks>
/// Server-side navigation redirects the browser to the new URL without taking Target into account.
/// </remarks>
/// <seealso cref="NavigateUrl" />
public void Navigate()
{
string sUrl = this.NavigateUrl;
if(sUrl.StartsWith("/"))
{
Context.Response.Redirect(sUrl, false);
}
else if(sUrl.StartsWith("?"))
{
Context.Response.Redirect(Context.Request.Path + sUrl, false);
}
else
{
Context.Response.Redirect(sUrl, false);
}
}
#endregion
#region Protected Properties
private System.Web.UI.AttributeCollection _properties;
internal System.Web.UI.AttributeCollection Properties
{
get
{
if(_properties == null)
{
StateBag oBag = new StateBag(true);
_properties = new System.Web.UI.AttributeCollection(oBag);
}
return _properties;
}
set
{
_properties = value;
}
}
protected string commandJavaScript;
internal NavigationNodeCollection nodes;
internal BaseNavigator navigator;
internal NavigationNode parentNode;
internal NavigationNode previousSibling;
internal string previousUrl;
internal string nextUrl;
internal NavigationNode nextSibling;
internal string PostBackID;
#endregion
#region Internal Methods
internal abstract NavigationNode AddNode();
/// <summary>
/// Generate the client-side command that should be executed when this node is selected.
/// </summary>
/// <returns>The client-side script in a string.</returns>
internal string GenerateClientCommand()
{
if(!this.AutoPostBackOnSelect && this.NavigateUrl != string.Empty)
{
if(this.Target == string.Empty)
{
this.commandJavaScript = "document.location.href='" + this.NavigateUrl + "'";
}
else
{
this.commandJavaScript = "window.open('" + this.NavigateUrl + "','" + this.Target + "')";
}
}
else
{
string sPostback = (this.navigator == null || Context == null || Page == null)? "__doPostBack(null,null)" :
Page.GetPostBackEventReference(this.navigator, this.PostBackID);
if(this.ClientSideCommand != string.Empty)
{
string sClientSideCommand = this.ClientSideCommand;
if(sClientSideCommand.EndsWith(";"))
{
sClientSideCommand = sClientSideCommand.Substring(0, sClientSideCommand.Length - 1);
}
this.commandJavaScript = string.Format("if({0}){{{1};}}", sClientSideCommand, sPostback);
}
else if(this.AutoPostBackOnSelect)
{
this.commandJavaScript = sPostback + ";";
}
else
{
this.commandJavaScript = string.Empty;
}
}
return commandJavaScript;
}
/// <summary>
/// Get the name to be used for the given attribute, taking into
/// consideration any attribute mappings.
/// </summary>
/// <param name="sAttribute">The default name of the attribute.</param>
/// <returns>The actual name of the attribute.</returns>
internal string GetAttributeVarName(string sAttribute)
{
if(this.navigator != null && navigator.CustomAttributeMappings.Count > 0)
{
for(int i = 0; i < navigator.CustomAttributeMappings.Count; i++)
{
CustomAttributeMapping oMapping = (CustomAttributeMapping)navigator.CustomAttributeMappings[i];
if(oMapping.To.ToLower() == sAttribute.ToLower())
{
return oMapping.From;
}
}
}
return sAttribute;
}
internal string GetVarAttributeName(string sAttribute)
{
if(this.navigator != null && navigator.CustomAttributeMappings.Count > 0)
{
for(int i = 0; i < navigator.CustomAttributeMappings.Count; i++)
{
CustomAttributeMapping oMapping = (CustomAttributeMapping)navigator.CustomAttributeMappings[i];
if(oMapping.From.ToLower() == sAttribute.ToLower())
{
return oMapping.To;
}
}
}
return sAttribute;
}
internal void ReadXmlAttributes(XmlAttributeCollection arAttributes)
{
// This takes over all attributes specified in Xml
foreach(XmlAttribute oAttribute in arAttributes)
{
this.Properties[oAttribute.Name] = oAttribute.Value;
}
}
internal bool IsPropertySet(string sPropertyName)
{
return (Properties[GetAttributeVarName(sPropertyName)] != null);
}
#endregion
}
#region Supporting types
public enum InheritBool
{
Inherit,
False,
True
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -