Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could also do as I have and just create a new class that inherits the UpdatePanel. I got the basis for this somewhere else but I don't remember where so I can't credit fully but I only tweaked it for this idea. I'm about to do the same for HTML Attributes (since the .attributes() collection is for css on the UpdatePanel instead of raw HTML attributes as with most other web.ui.controls).</p> <p>UPDATED: I've updated to include some other customization I've made that allow for ANY attribute to be added. Really this duplicates the first customization except that the 1st creates a fairly standard approach where this is completely flexible (thus not standard).</p> <pre><code>Imports System.ComponentModel Imports System.Collections Imports System.Web.UI Namespace Controls Public Class UpdatePanelCss Inherits UpdatePanel Private _cssClass As String Private _tag As HtmlTextWriterTag = HtmlTextWriterTag.Div Public HtmlAttributes As New HtmlAttributes &lt;DefaultValue("")&gt; _ &lt;Description("Applies a CSS style to the panel.")&gt; _ Public Property CssClass() As String Get Return If(_cssClass, [String].Empty) End Get Set(ByVal value As String) _cssClass = value End Set End Property ' Hide the base class's RenderMode property since we don't use it &lt;Browsable(False)&gt; _ &lt;EditorBrowsable(EditorBrowsableState.Never)&gt; _ &lt;DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)&gt; _ Public Shadows Property RenderMode() As UpdatePanelRenderMode Get Return MyBase.RenderMode End Get Set(ByVal value As UpdatePanelRenderMode) MyBase.RenderMode = value End Set End Property &lt;DefaultValue(HtmlTextWriterTag.Div)&gt; _ &lt;Description("The tag to render for the panel.")&gt; _ Public Property Tag() As HtmlTextWriterTag Get Return _tag End Get Set(ByVal value As HtmlTextWriterTag) _tag = value End Set End Property Protected Overrides Sub RenderChildren(ByVal writer As HtmlTextWriter) If IsInPartialRendering Then ' If the UpdatePanel is rendering in "partial" mode that means ' it's the top-level UpdatePanel in this part of the page, so ' it doesn't render its outer tag. We just delegate to the base ' class to do all the work. MyBase.RenderChildren(writer) Else ' If we're rendering in normal HTML mode we do all the new custom ' rendering. We then go render our children, which is what the ' normal control's behavior is. writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID) If CssClass.Length &gt; 0 Then writer.AddAttribute(HtmlTextWriterAttribute.[Class], CssClass) End If If HtmlAttributes.Count &gt; 0 Then For Each ha As HtmlAttribute In HtmlAttributes writer.AddAttribute(ha.AttrName, ha.AttrVal) Next End If writer.RenderBeginTag(Tag) For Each child As Control In Controls child.RenderControl(writer) Next writer.RenderEndTag() End If End Sub End Class Public Class HtmlAttribute Private PAttrName As String Private PAttrVal As String Public Sub New(AttrName As String, AttrVal As String) PAttrName = AttrName PAttrVal = AttrVal End Sub Public Property AttrName() As String Get Return PAttrName End Get Set(value As String) PAttrName = value End Set End Property Public Property AttrVal() As String Get Return PAttrVal End Get Set(value As String) PAttrVal = value End Set End Property End Class Public Class HtmlAttributes Inherits CollectionBase Public ReadOnly Property Count() As Integer Get Return List.Count End Get End Property Default Public Property Item(ByVal index As Integer) As HtmlAttribute Get Return CType(List.Item(index), HtmlAttribute) End Get Set(ByVal Value As HtmlAttribute) List.Item(index) = Value End Set End Property Public Function Add(ByVal item As HtmlAttribute) As Integer Return List.Add(item) End Function Public Sub Remove(ByVal index As Integer) If index &lt; List.Count AndAlso List.Item(index) IsNot Nothing Then List.RemoveAt(index) Else Throw New Exception(String.Concat("Index(", index.ToString, ") is not valid. List only has ", List.Count.ToString, " items.")) End If End Sub Public Sub Remove(ByRef hAttribute As HtmlAttribute) If List.Count &gt; 0 AndAlso List.IndexOf(hAttribute) &gt;= 0 Then List.Remove(hAttribute) Else Throw New Exception("Object does not exist in collection.") End If End Sub End Class End Namespace </code></pre> <p><strong>C# conversion via <a href="http://www.developerfusion.com/" rel="nofollow">http://www.developerfusion.com/</a>:</strong></p> <pre><code>using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.ComponentModel; using System.Web.UI; namespace Controls { public class UpdatePanelCss : UpdatePanel { private string _cssClass; private HtmlTextWriterTag _tag = HtmlTextWriterTag.Div; public HtmlAttributes HtmlAttributes = new HtmlAttributes(); [DefaultValue("")] [Description("Applies a CSS style to the panel.")] public string CssClass { get { return _cssClass ?? String.Empty; } set { _cssClass = value; } } // Hide the base class's RenderMode property since we don't use it [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public new UpdatePanelRenderMode RenderMode { get { return base.RenderMode; } set { base.RenderMode = value; } } [DefaultValue(HtmlTextWriterTag.Div)] [Description("The tag to render for the panel.")] public HtmlTextWriterTag Tag { get { return _tag; } set { _tag = value; } } protected override void RenderChildren(HtmlTextWriter writer) { if (IsInPartialRendering) { // If the UpdatePanel is rendering in "partial" mode that means // it's the top-level UpdatePanel in this part of the page, so // it doesn't render its outer tag. We just delegate to the base // class to do all the work. base.RenderChildren(writer); } else { // If we're rendering in normal HTML mode we do all the new custom // rendering. We then go render our children, which is what the // normal control's behavior is. writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID); if (CssClass.Length &gt; 0) { writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClass); } if (HtmlAttributes.Count &gt; 0) { foreach (HtmlAttribute ha in HtmlAttributes) { writer.AddAttribute(ha.AttrName, ha.AttrVal); } } writer.RenderBeginTag(Tag); foreach (Control child in Controls) { child.RenderControl(writer); } writer.RenderEndTag(); } } } public class HtmlAttribute { private string PAttrName; private string PAttrVal; public HtmlAttribute(string AttrName, string AttrVal) { PAttrName = AttrName; PAttrVal = AttrVal; } public string AttrName { get { return PAttrName; } set { PAttrName = value; } } public string AttrVal { get { return PAttrVal; } set { PAttrVal = value; } } } public class HtmlAttributes : CollectionBase { public int Count { get { return List.Count; } } public HtmlAttribute this[int index] { get { return (HtmlAttribute)List[index]; } set { List[index] = value; } } public int Add(HtmlAttribute item) { return List.Add(item); } public void Remove(int index) { if (index &lt; List.Count &amp;&amp; List[index] != null) { List.RemoveAt(index); } else { throw new Exception(string.Concat("Index(", index.ToString(), ") is not valid. List only has ", List.Count.ToString(), " items.")); } } public void Remove(ref HtmlAttribute hAttribute) { if (List.Count &gt; 0 &amp;&amp; List.IndexOf(hAttribute) &gt;= 0) { List.Remove(hAttribute); } else { throw new Exception("Object does not exist in collection."); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload