Total Pageviews

Tuesday 29 May 2012

C# XML serialization attributes

C# XML serialization attributes



Where Attribute Function
class XmlRoot name a root element
field, property, parameter, or return value XmlAttribute serialized as an XML attribute
field, property, parameter, or return value XmlElement serialized as an XML element
field, property, parameter, or return value of type XmlAttribute[] XmlAnyAttribute collects all unknown attributes
field, property, parameter, or return value of type XmlElement[] XmlAnyElement collects all unknown elements
field, property XmlIgnore not part of serialization
field, property, parameter, or return value that returns an array of complex objects XmlArray
field, property, parameter, or return value that returns an array of complex objects XmlArrayItem
field, property, parameter, or return value XmlChoiceIdentifier
field that is an enumeration identifier XmlEnum serialization of an enumeration member
derived class declarations, and return values of public methods (WSDL) XmlInclude should be included when generating schemas
properties and fields XmlText serialized as XML text
class declarations XmlType name and namespace of the XML type

Limitations of XML serialization

  • Does not handle mixed mode (all mixed items are gathered in one XmlText)
  • Serialization of interfaces (there is currently no way to specify an underlying type for deserialization)
  • Due to dynamic code generation that accesses the serialized types from outside all the members and classes to be serialized MUST be public.
Alternative: implement IXmlSerializable if you need bigger flexibility

link: http://www.color-of-code.de/index.php/cheat-sheets/programming/c-serialization-attributes

Friday 25 May 2012

How to show progressing of ASP.NET postback

When the ASP.NET page is posted back or partially posted back, generally there takes time to process the request and render the page again. in that time user may confuse whether the process is executing or not.
In this case we can show an animation of waiting/busy. I want to discuss how to do it.
we can do it using the following ways...

Way 1#
Set ScriptManager Property AsyncPostBackTimeout="0" .zero means infinity.
and use the following scripts


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%--
Controls & Form's element here 
--%>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="up1" runat="server" AssociatedUpdatePanelID ="UpdatePanel1" >
    <ProgressTemplate>
       <div align="center" style="position:absolute;left:45%;top:45%">
                <img src="Images/please_wait.gif" alt="Please wait...." />
       </div>
    </ProgressTemplate>
</asp:UpdateProgress>

<ajax:UpdatePanelAnimationExtender ID="AnimationExtender1" runat="server" Enabled="True" TargetControlID="UpdatePanel1">
       <Animations>
            <OnUpdating>
             <Parallel duration="0">
                <ScriptAction Script="onUpdating();" />
                 <EnableAction AnimationTarget="ControlIDToDisableDuringUpdating"  Enabled="false"/>
                .......
                .....
             </Parallel>
            </OnUpdating>
            <OnUpdated>
              <Parallel duration="0">
                <ScriptAction Script="onUpdated();" />
                <EnableAction AnimationTarget=" ControlIDToEnableAfterUpdate"  Enabled="true"/>
                 .......
                 .......
              </Parallel>
            </OnUpdated>
        </Animations>
 </ajax:UpdatePanelAnimationExtender>

And in Web.Config file  to add Assembly 

<pages enableSessionState="true" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
      <controls>
    <add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagPrefix="ajax" />
      </controls>
</pages>


Way 2#
Set ScriptManager Property AsyncPostBackTimeout="0" .zero means infinity.
and use the following scripts


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%--
Controls & Form's element here 
--%>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="up1" runat="server" AssociatedUpdatePanelID ="UpdatePanel1" >
    <ProgressTemplate>

 <div id="dlg" style="z-index:999;background-color: Blue;height: 100%;left: 0;opacity: 0.2;position: absolute;top: 0; width: 100%;vertical-align:middle;text-align:center;" align="center">

  <img alt="Please Wait..." src="Images/please_wait.gif" style="z-index:9999;margin:20%"  />

</div>

    </ProgressTemplate>
</asp:UpdateProgress>




Pic:  please_wait.gif