Monday, 24 December 2012

 Click Here to Download JQueryImageOverlay.zip

Image overlay means give text caption to image. Using Image overlay we can provide more details regarding image on mouse hover of image. This overlay is common in modern websites. We are using JQuery Image Overlay Plugin. This is a javascript file which you found online as well as we place this javascript in our example so you can download that from our given asp.net example.

There are many options and advance settings provided by Overlay Plugin javascript "jquery.ImageOverlay.js". You can set without any options for simple purpose. There are options like border color, overlay origin, overlay color, and overlay text color, overlay speed, overlay speed out etc.

By setting this option you made you custom overlay, like border cover , text color , different In and Out overlay animation etc..
You can also use JQuery MetaData Plugin "jquery.metadata.js" to display meta data information in overlay.

Here is example for this.
In this example we take several images to display various uses of Image overlay with Asp.Net.

Wednesday, 19 December 2012

You can bind list of strings to gird view and display very uniform manner in a very easy way. List may be a generic list of strings. Generic List class is available in "System.Collections.Generic" namespace. We are using "DataSource" property of Grid view to set data source and "DataBind" method to bind data.

Here is example for this.

Thursday, 13 December 2012

There are many situations where you want to list of stored procedures from your database and it's useful details like , SP created date , modify date etc.. using sql query.
There is simple way to get these information using sql query.
We are using "sys.procedures" system table to get list and details.
Here is the sql script.

Friday, 7 December 2012

There are many situations where you want to list of tables and it's useful details like , table created date , modify date etc.. using sql query. There is simple way to get these informations using sql query.
We are using "sys.tables" system table to get list and details.
Here is the sql script.

SQL Query :
select * from sys.tables

Output : 

(To view original image , click on image)










This is the very useful SQL Server Scripts.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



Tuesday, 4 December 2012

Click to Download C# Example ImplementIHTTPModuleInterfaceInCSharp.zip
Click to Download VB.NET Example ImplementIHTTPModuleInterfaceInVBNET.zip

By Implementing IHttpModule interface we can plug classes into the request-processing pipeline. HTTP Module class do this by hooking into a application events as it processes the HTTP request.
To create an HttpModule, we simply create a class that implement the System.Web.IHttpModule interface.This interface requires you to implement Init and Dispose methods.

The Init method is the basic primary method. In this method we implement HttpModule functionality. You can register different events in to the Init method. Init method has a single parameter it's an object of HttpApplication class and it's name is "context".

To use this module, we must include the module in the request processing pipeline so that ASP.NET know that. We can do this to modify the web.config file.
For that you have to add an <httpModules> section to your web.config file.

Here is the generic format :
The generic format of the <httpModules> section is
<httpModules>
        <add name="[modulename]" type="[namespace.classname, assemblyname]" />
</httpModules>

If you want to deploy your application to an IIS 7 server, you must also add the module configuration to the
<system.webServer> configuration section.

<modules>
    <add name="[modulename]" type="[namespace.classname, assemblyname]" />
</modules>

If we create our HttpModule in the App_Code directory of an ASP.NET Web site. For that we use the text “App_Code” as the assembly name, which tells ASP.NET that  module is located in the dynamically created assembly.

If we create HttpModules as a separate class library, in this case we use the assembly name of the library.

Here is example for this.

Sunday, 18 November 2012

There is a situation in drop down list where first item is "[Select]" and you need to make mandatory selection from drop down list except "[Select]".
Means, user must select value from drop down list but did not allow to select first element "[Select]". We can achieve this using required field validator control. For that we need to set "InitialValue" property.

Here is example for this.
In this example we take one product drop down list control in this list we list out all products, But the First Item is "[Select]" and it's value is "-1" in product drop downlist.
And We take one Required Field Validator control and set it's ValidateControl property to product drop down list id. We also set "InitialValue=-1" property.
We also took one button so that on click of button required field valdator control validate user input.
In this example we set InitialValue to -1 so that , if user select "[Select]" item from drop down list and click on "Save" button Validator control executed and validation message display on screen.
You can see that validation message in output.

Friday, 16 November 2012

You can get parent child hierarchy records or category sub category records or recursive records from table in sql server and display as a tree structure.
We are using A common table expression (CTE)  to get result. In fact we are using Recursive CTE to get this recursive data.

Here is example for this.
In this example we take one table "category_master". This table contains recursive records. This table has "category_id" , "category_name" and "parent_category_id" columns. "parent_category_id" column contain reference of "category_id". We can insert "N - Level" of parent child relationship records. We retrieve those records using recursive "CTE" and we can also do Hierarchy level by applying spacing so it's look like tree structure.

Wednesday, 7 November 2012

There is a situation where you want to put asp button in telerik Rad AjaxPanel and execute some javascript function using "onClientClick" event and base on that javascript function you need to execute server side code, i.e If javascript function return false then do nothing else if return true it will execute server side code. Here is solution for this.
Without do any trick this code do not work If you simply set "onClientClick" with javascript function without update panel this work but under Rad AjaxPanel this is not execute server side code after executing javascript function.

This Do not work :  onClientClick="return ConfirmDeleteMessage();"

This will Work :  OnClientClick="if (!ConfirmDeleteMessage('Are you sure you want to delete ? ')) { return false; }"

Here is example for this.
In this example we take one asp button and put this button inside Rad AjaxPanel.
And also we take on javascript function, in this function we take confirmation window and ask use for allow delete message.
On clicking on the "Ok" server side code is being executed.

ASPX Code : 
   <telerik:radscriptblock id="RadScriptBlock1" runat="server">
       <script type="text/javascript">
           function ConfirmDeleteMessage(strMessage) {
               if (window.confirm(strMessage)) {
                   return true;
               }
               else {
                   return false;
               }
           }
        </script>
    </telerik:radscriptblock>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:radajaxpanel id="pnlMessage" runat="server">
        <div>
            <asp:Label runat="server" ID="lblMessage" ></asp:Label><br />
            <asp:Button runat="server" ID="btnDeleteItem" Text="Delete Item" 
                                     OnClientClick="if (!ConfirmDeleteMessage('Are you sure you want to delete ? ')) { return false; }"
                                     OnClick="btnDeleteItem_Click"  />
            <br /><br />
         </div>
         </telerik:radajaxpanel>
     </form>

C# Examples :
    protected void btnDeleteItem_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "Server side code executed.";
        
    }

VB.net Examples :
    Protected Sub btnDeleteItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        lblMessage.Text = "Server side code executed."
    End Sub

Output (After Click on "Delete Item" button confirmation dialog box open) :


Output (After click n "Ok" button of confirmation dialog box server side code of "Delete Item" button  executed.) : 


This article is very useful for .Net Beginners.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.




Thursday, 1 November 2012

You can insert value in identity column manually using INSERT statement using "IDENTITY_INSERT" property. You need to set IDENTITY_INSERT property to ON to allow identity insert value.
If there is already IDENTITY_INSERT property ON for particular table and again you set to ON It will raise error "states SET IDENTITY_INSERT is already ON and reports the table it is set ON".
After Set ON and Insert records we need to set OFF to avoid unnecessary errors.
You need permission to set this property. By default "sysadmin" server role and the "db_owner" and "db_ddladmin" database role and the object owner has permission.

Here is example for this.
In this example we take one database table "product_master". This table has one identity column "product_id" and other column "product_name".
Now we are inserting some records and we can see that it's identity column has serial unique number. After that we delete one records from middle of that records. So now one gap introduce in serial unique number. Now if you want to insert another product it did not generate that missing serial number it will simply generate greater value from existing numbers.
Suppose we have certain situations where we want to insert that particular identity number record. So at that time we can use "IDENTITY_INSERT" property. You can see in screen shot that there is product_id="5" record is deleted and is missing from list. Now we again insert that identity value using "IDENTITY_INSERT".

SQL Query :
SET IDENTITY_INSERT [product_master] ON
INSERT INTO product_master (product_id,product_name) values(5,'USB')
SET IDENTITY_INSERT [product_master] OFF

Output (Missing Record Id Sequence) : 


Output (After inserting Missing Record Id Sequence) :


This is the very useful SQL Server Scripts.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



Monday, 29 October 2012

 Click Here to Download ImplementCustomException.zip
You can also called that create user defined exception class in asp.net.
There is a situations where you need to create and handle a custom exception for handling runtime’s exception for application-specific exceptions.
In this example we provide both C#.Net Example and VB.Net Example.

Let's look how this mechanism works.
For that we need to create a serializable class that extends the System.Exception class, and ass some constructors and properties to manipulate the data members.
You can throw custom exception class object exception in Try block and it will handle in catch block. Mark your custom exception class as sealed if you do not wish other exception classes to extend it. You need to Implement three public constructors with specific signature and they call base class constructor.

You also need to make custom exception class serializable so that the runtime can marshal instances of your exception. If your exception class declares custom data members, so you must override the ISerializable. GetObjectData method of the Exception class as well as implement a deserialization constructor with appropriate signature. If your exception class is sealed then mark the deserialization constructor as private, otherwise, mark it as protected. The GetObjectData method and deserialization constructor must call the equivalent base class method to allow the base class to serialize and deserialize its data correctly.

Here is example for this.

Friday, 19 October 2012


This is a situations where you have an string array which contains some string element or values and some integer values and we want to parse that integer values from that List or array and retrieve only integer values. We can do with the help of LINQ. We can create an extension method of linq and achieve this.
This LINQ extension method is very useful.

Here is example for this.
In this example we take one List of string object. This List of string object contains both integer and string values.We parse that List of string object and get integer values from that.

In Vb.Net Example we need to add "Module" to create custom LINQ Extension method.

Monday, 15 October 2012

Click Here to Download ImplementIComparableInterface.zip

You can compare two object of same class with your predefine rules. You can also say comparison between two objects. 
You can provide compare custom types with your predefined business rules. This also allow to sort collections of instances of those types.
For comparison we implement generic System.IComparable<T> interface. For the comparison of a type based on more than one characteristic, we need to create separate types that implement the generic System.Collections.Generic.IComparer<T> interface.

If you compare two different object of same class with equal (=) operator , at that time this will check only reference location number, this will not check actual fields value property. To avoid this we need to implement IComparable interface and implements it's "CompareTo" Method.

You can call this method like this "X.CompareTo(Y)". X and Y is the object of custom class.
This method return Three possible values.

  • If X value is less than Y value, it will return less than zero (for example, -1).
  • If X value same value as Y value , it will return zero.
  • If X value is greater than Y value, It will return greater than zero (for example, 1).

Here is example for this.

Monday, 8 October 2012

We often get requirement to allow only numeric decimal value in textbox for validation purpose, And also we have to specify number of decimal places. We can use ASP.Net RegularExpressionValidator control for this. In this control we can specify regex expression for validation.

The regex expression is "^[+]?[0-9]\d{0,5}(\.\d{1,4})?%?$" .
This regex allow only positive numeric value of maximum six digit and maximum four digit decimal value. The maximum allowed value by this regex is "999999.9999". You can change this accroding to your requirement.

Here is example.

Thursday, 4 October 2012

For validation purpose in your project at some places you put text boxes that accept only integer value i.e. 1, 20 , 50, 200 etc... To put validation on that text boxes and allow only integer value you can use ASP.NET Regular Expression Validator Control. In this control we make one regex expression and do validation for that text box.
The regex expression is "^\d+$" .

Here is example.

Monday, 1 October 2012

Click Here to Download ImplementICloneableInterface.zip

There is a need where you wan to clone an object for your custom requirement you need to "ICloneable" Interface and Implement Clone() Method, the inbuilt Clone() method does not fulfill custom requirement.
When you assign one value type to another, at that time a copy of the value is created. No link exists between the those two values and changes in one value will not affect the other value.
 However, when we assign one reference type to another (excluding strings), at that time a new copy of the reference type did not created. but , both reference types refer to the same object, and changes into the value of the one object are reflected in other objects.
To create a actual true copy of a reference type object, we must clone the object.
For cloning we are using ICloneable Interface.
We are using "MemberwiseClone" method for shallow copy clone.

Here is example:
In this example we take one "Books" class object and implement "ICloneable"  Interface on that. After that we create one object of "Books" class and set its property after that we create another "Books" object and set our original object by "Clone" Method. You can see in output that If we change in either property of object that object value does not affected earch others.
If you remove the ICloneable Interface on class and directly assign one object to another object and making change in one object's property It will automatically change others property.

C# Examples :
    public class Books : ICloneable
    {
        public string Title { get; set; }
        public string ISBN { get; set; }
        public DateTime ReleaseDate { get; set; }
        public int Pages { get; set; }
        public int PublisherId { get; set; }

        public object Clone()
        {
            return MemberwiseClone();
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Books objBook = new Books { Title = "ASP.NET", ISBN = "asp1", ReleaseDate = DateTime.Parse("11/11/2010"), Pages = 200, PublisherId = 1 };

        Books objTmp = (Books) objBook.Clone();
        Response.Write("<b>Original Book Object:</b> ");
        Response.Write("</br>Title : " + objBook.Title);
        Response.Write("</br>ISBN : " + objBook.ISBN);
        Response.Write("</br>ReleaseDate : " + objBook.ReleaseDate);
        Response.Write("</br>Pages : " + objBook.Pages);
        Response.Write("</br></br>");
        ////Make change in copy object
        objTmp.Title = "C#";
        Response.Write("</br><b>After Change In Copy Object Book Object Unaffected:</b>");
        Response.Write("</br>Title : " + objBook.Title);
        Response.Write("</br>ISBN : " + objBook.ISBN);
        Response.Write("</br>ReleaseDate : " + objBook.ReleaseDate);
        Response.Write("</br>Pages : " + objBook.Pages);
        Response.Write("</br></br>");

        objBook.Title = "SQL";

        ////Clone object
        
        Response.Write("</br><b>Clone Object:</b>");
        Response.Write("</br>Title : " + objTmp.Title);
        Response.Write("</br>ISBN : " + objTmp.ISBN);
        Response.Write("</br>ReleaseDate : " + objTmp.ReleaseDate);
        Response.Write("</br>Pages : " + objTmp.Pages);
        Response.Write("</br></br>");

       
    }

VB.net Examples :
    Public Class Books
        Implements ICloneable

        Public Property Title() As String
        Public Property ISBN As String
        Public Property ReleaseDate As Date
        Public Property Pages As Integer
        Public Property PublisherId As Integer

        Public Function Clone() As Object Implements ICloneable.Clone
            Return MemberwiseClone()
        End Function
    End Class

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objBook As Books = New Books With {.Title = "ASP.NET", .ISBN = "asp1", .ReleaseDate = DateTime.Parse("11/11/2010"), .Pages = 200, .PublisherId = 1}

        Dim objTmp As Books = CType(objBook.Clone(), Books)
        Response.Write("<b>Original Book Object:</b> ")
        Response.Write("</br>Title : " & objBook.Title)
        Response.Write("</br>ISBN : " & objBook.ISBN)
        Response.Write("</br>ReleaseDate : " & objBook.ReleaseDate)
        Response.Write("</br>Pages : " & objBook.Pages)
        Response.Write("</br></br>")
        '//Make change in copy object
        objTmp.Title = "C#"
        Response.Write("</br><b>After Change In Copy Object Book Object Unaffected:</b>")
        Response.Write("</br>Title : " & objBook.Title)
        Response.Write("</br>ISBN : " & objBook.ISBN)
        Response.Write("</br>ReleaseDate : " & objBook.ReleaseDate)
        Response.Write("</br>Pages : " & objBook.Pages)
        Response.Write("</br></br>")

        objBook.Title = "SQL"

        '//Clone object

        Response.Write("</br><b>Clone Object:</b>")
        Response.Write("</br>Title : " & objTmp.Title)
        Response.Write("</br>ISBN : " & objTmp.ISBN)
        Response.Write("</br>ReleaseDate : " & objTmp.ReleaseDate)
        Response.Write("</br>Pages : " & objTmp.Pages)
        Response.Write("</br></br>")

    End Sub

Output :


Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



Friday, 28 September 2012

You can set holidays or note on particular date in calendar control. For that we are using "DayRender" Event of the calendar control. This event call on each day cell render, so we can check particular date make set tool tips and also set our user defined backcolor or apply any style in that particular day cell.
You can see tool tip on mouse over of that particular day.

Here is example for this.
In this example we display holidays and notes with two different colors.

ASPX Code :
        <asp:Calendar ID="Calendar1" runat="server"  BackColor="#FFFFCC" 
            BorderColor="#FFCC66" DayNameFormat="Shortest" Font-Names="Verdana" 
            Font-Size="8pt" ForeColor="#663399" Height="200px" Width="220px" 
            BorderWidth="1px" ShowGridLines="True" OnDayRender="Calendar1_DayRender" SelectionMode="None" >
            <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
            <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
            <OtherMonthDayStyle ForeColor="#CC9966" />
            <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
            <SelectorStyle BackColor="#FFCC66" />
            <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" 
                ForeColor="#FFFFCC" />
            <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
        </asp:Calendar>

C# Examples :
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {

        switch(e.Day.Date.ToString("dd/MM/yyyy"))
        {
            case "01/09/2012":
                e.Cell.ToolTip = "Holiday 1";
                e.Cell.BackColor = System.Drawing.Color.Red;
                break;
            case "05/09/2012":
                e.Cell.ToolTip = "Holiday 2";
                e.Cell.BackColor = System.Drawing.Color.Red;
                break;
            case "20/09/2012":
                e.Cell.ToolTip = "Note : Meeting with client";
                e.Cell.BackColor = System.Drawing.Color.Yellow;
                break;

        }

    }

VB.net Examples :
    Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)

        Select Case e.Day.Date.ToString("dd/MM/yyyy")
            Case "01/09/2012"
                e.Cell.ToolTip = "Holiday 1"
                e.Cell.BackColor = System.Drawing.Color.Red
                Exit Sub
            Case "05/09/2012"
                e.Cell.ToolTip = "Holiday 2"
                e.Cell.BackColor = System.Drawing.Color.Red
                Exit Sub
            Case "20/09/2012"
                e.Cell.ToolTip = "Note : Meeting with client"
                e.Cell.BackColor = System.Drawing.Color.Yellow
                Exit Sub

        End Select

    End Sub

Output :
Set Holidays or Note on particular date in asp calendar control

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



Wednesday, 26 September 2012

Click Here to Download SelectWeekInCalendarControl.zip

You can select entire week or month in asp.net calendar control and get it's selected dates.
You can achieve using SelectionMode property of calendar control.
Selection mode property has an enum and it has four selection mode like Day , DayWeek , DayWeekMonth and None.

Here is example for this.
In this example we take calendar control and we set selection mode as DayWeek. When we set this mode after that calender control automatically add one column for select particular week.
You can specify "DayWeekMonth" value to selection mode property for select entire month and also specify "SelectMonthText" property to display select text.

ASPX Code :
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black" 
            Font-Names="Times New Roman" Font-Size="10pt" ForeColor="Black" Height="220px"
                NextPrevFormat="FullMonth" Width="400px" SelectionMode="DayWeek" 
            DayNameFormat="Shortest" TitleFormat="Month" SelectWeekText="Select" >
                <DayHeaderStyle Font-Bold="True" Font-Size="7pt" ForeColor="#333333" 
                    Height="10pt" BackColor="#CCCCCC" />
                <DayStyle Width="14%" />
                <NextPrevStyle Font-Size="8pt" ForeColor="White" />
                <OtherMonthDayStyle ForeColor="#999999" />
                <SelectedDayStyle BackColor="#CC3333" ForeColor="White" />
                <SelectorStyle BackColor="#CCCCCC" Font-Bold="True" Font-Names="Verdana" 
                    Font-Size="8pt" ForeColor="#333333" Width="1%" />
                <TitleStyle BackColor="Black" Font-Bold="True"
                    Font-Size="13pt" ForeColor="White" Height="14pt" />
                <TodayDayStyle BackColor="#CCCC99" />
        </asp:Calendar>
         <br />

         <asp:Button runat="server" ID="btnGetSelectedDate" Text="Get Selected Date" 
        /> &nbsp;&nbsp;&nbsp;
         <b>Date : </b><asp:Label runat="server" ID="lblDate" ></asp:Label>

C# Examples :
    protected void btnGetSelectedDate_Click(object sender, EventArgs e)
    {
        foreach (DateTime dt in Calendar1.SelectedDates)
        {
            lblDate.Text = lblDate.Text + " <br/> " + dt.ToString("dd/MM/yyyy");
        }
    }

VB.net Examples :
    Protected Sub btnGetSelectedDate_Click(ByVal sender As Object, ByVal e As EventArgs)
        For Each dt As DateTime In Calendar1.SelectedDates
            lblDate.Text = lblDate.Text + " <br/> " & dt.ToString("dd/MM/yyyy")
        Next
    End Sub

Output :



 For Beginning .Net articles. Click Here...

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



 

Monday, 24 September 2012

Click Here to Download ProcessRSSorATOMFeed.zip

You can process the content of an Atom 1.0 or RSS 2.0 feed to extract or get details of the feed. .Net framework provide classes to parse the feed data.
We are using System.ServiceModel.Syndication.SyndicationFeedFormatter and System.ServiceModel.Syndication.SyndicationFeed classes.

The SyndicationFeedItem  and SyndicationFeed classes gives a generic abstraction of Atom 1.0 and RSS 2.0 feeds and feed items, and provide a common interface to simplify the processing of both feed types. The Rss20FeedFormatter class allows to create a SyndicationFeed object from an RSS 2.0 feed, and the Atom10FeedFormatter class provides support for Atom 1.0 feeds. Both classes are available in the System.ServiceModel.Syndication namespace.
We are using "ReadFrom" method and "Feed" property of these classes.

Here is example for this.
In this example we read the feed and display it's details.

C# Examples :
        Uri objFeedUrl = null;
        string strUrl = "http://jayeshsorathia.blogspot.com/rss.xml";
        if (strUrl.Length == 0 || String.IsNullOrEmpty(strUrl) || !Uri.TryCreate(strUrl, UriKind.RelativeOrAbsolute, out objFeedUrl))
        {
            Response.Write("Invalid feed.");
            return;
        }

        // Create the web request.
        WebRequest objReqFeed = WebRequest.Create(objFeedUrl);

        // Get the data from the feed.
        WebResponse objResFeed = objReqFeed.GetResponse();

        
        SyndicationFeedFormatter objFeedFormatter = null;

        XElement feed = XElement.Load(objResFeed.GetResponseStream());

        // Check for the feed type
        if (feed.Name.LocalName == "rss")
        {
            objFeedFormatter = new Rss20FeedFormatter();
        }
        else if (feed.Name.LocalName == "feed")
        {
            objFeedFormatter = new Atom10FeedFormatter();
        }
        else
        {
            Response.Write("Unsupported feed type: " + feed.Name.LocalName);
            return;
        }

        // Read the feed data into the formatter.
        objFeedFormatter.ReadFrom(feed.CreateReader());

        // Display feed Details

        Response.Write("<b>Feed Title : </b>" + objFeedFormatter.Feed.Title.Text);
        Response.Write("<br/><br/>");
        Response.Write("<b>Feed Description : </b>" + objFeedFormatter.Feed.Description.Text);
        Response.Write("<br/><br/>");
        Response.Write("<b>Items in the Feed : </b>");
        Response.Write("<br/><br/>");
        
        foreach (var objItem in objFeedFormatter.Feed.Items)
        {
            Response.Write("<b>Title : </b> " + objItem.Title.Text);
            if (objItem.Summary != null)
            {
                Response.Write("<br/><b>Summary : </b>" + objItem.Summary.Text);
            }

            Response.Write("<br/><b>Publish Date : </b>" + objItem.PublishDate);
            Response.Write("<br/><br/>");
        }

VB.net Examples :
        Dim objFeedUrl As Uri = Nothing
        Dim strUrl As String = "http://jayeshsorathia.blogspot.com/rss.xml"
        If strUrl.Length = 0 Or String.IsNullOrEmpty(strUrl) Or Not Uri.TryCreate(strUrl, UriKind.RelativeOrAbsolute, objFeedUrl) Then
            Response.Write("Invalid feed.")
            Return
        End If

        ' Create the web request.
        Dim objReqFeed As WebRequest = WebRequest.Create(objFeedUrl)

        ' Get the data from the feed.
        Dim objResFeed As WebResponse = objReqFeed.GetResponse()


        Dim objFeedFormatter As SyndicationFeedFormatter = Nothing

        Dim feed As XElement = XElement.Load(objResFeed.GetResponseStream())

        ' Check for the feed type
        If feed.Name.LocalName = "rss" Then
            objFeedFormatter = New Rss20FeedFormatter()
        ElseIf feed.Name.LocalName = "feed" Then
            objFeedFormatter = New Atom10FeedFormatter()
        Else
            Response.Write("Unsupported feed type: " & feed.Name.LocalName)
            Return
        End If

        ' Read the feed data into the formatter.
        objFeedFormatter.ReadFrom(feed.CreateReader())

        ' Display feed Details

        Response.Write("<b>Feed Title : </b>" & objFeedFormatter.Feed.Title.Text)
        Response.Write("<br/><br/>")
        Response.Write("<b>Feed Description : </b>" & objFeedFormatter.Feed.Description.Text)
        Response.Write("<br/><br/>")
        Response.Write("<b>Items in the Feed : </b>")
        Response.Write("<br/><br/>")

        Dim objItem As SyndicationItem
        For Each objItem In objFeedFormatter.Feed.Items
            Response.Write("<b>Title : </b> " & objItem.Title.Text)
            If Not objItem.Summary Is Nothing Then
                Response.Write("<br/><b>Summary : </b>" & objItem.Summary.Text)
            End If

            Response.Write("<br/><b>Publish Date : </b>" & objItem.PublishDate.ToString())
            Response.Write("<br/><br/>")
        Next

Output : 
Read the Content of an Atom or RSS Feed output
(To view original image , click on image)

This is very useful .Net Tips.

For Beginning .Net articles. Click Here...

To learn more regarding XML. Click Here...

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



Saturday, 22 September 2012

Click Here to Download Sample MultipleDateSelectionInCalendarControl.zip

You can select multiple dates in calendar control.
There is a no direct way to select multiple dates in calendar control. You need to write some code for that.

Here is example for this.
In this example we take one calendar control and select multiple dates in that control and we display that selected dates in label.

ASPX Code : 
      <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black" 
            Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px"
                NextPrevFormat="ShortMonth" OnPreRender="Calendar1_PreRender" Width="330px" 
                OnSelectionChanged="Calendar1_SelectionChanged" BorderStyle="Solid" 
            CellSpacing="1">
                <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" 
                    Height="8pt" />
                <DayStyle BackColor="#CCCCCC" />
                <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
                <OtherMonthDayStyle ForeColor="#999999" />
                <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                <TitleStyle BackColor="#333399" Font-Bold="True"
                    Font-Size="12pt" ForeColor="White" BorderStyle="Solid" Height="12pt" />
                <TodayDayStyle BackColor="#999999" ForeColor="White" />
        </asp:Calendar>

         <br />
         <br />
         <asp:Button runat="server" ID="btnGetSelectedDate" Text="Get Selected Date" 
            onclick="btnGetSelectedDate_Click" /> &nbsp;&nbsp;&nbsp;<br />
         <b>Selected Dates : </b><asp:Label runat="server" ID="lblDate" ></asp:Label>


C# Examples :
    protected void Calendar1_PreRender(object sender, EventArgs e)
    {
        
        Calendar1.SelectedDates.Clear();

        foreach (DateTime dt in MultipleSelectedDates)
        {
            Calendar1.SelectedDates.Add(dt);
        }
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {

        if (MultipleSelectedDates.Contains(Calendar1.SelectedDate))
        {
            MultipleSelectedDates.Remove(Calendar1.SelectedDate);
        }
        else
        {
            MultipleSelectedDates.Add(Calendar1.SelectedDate);
        }
        
        ViewState["MultipleSelectedDates"] = MultipleSelectedDates;
    }
   

    public List<DateTime> MultipleSelectedDates
    {
        get
        {
            if (ViewState["MultipleSelectedDates"] == null)

                ViewState["MultipleSelectedDates"] = new List<DateTime>() ;
            return (List<DateTime>)ViewState["MultipleSelectedDates"];
        }
        set
        {
            ViewState["MultipleSelectedDates"] = value;
        }
    }


    protected void btnGetSelectedDate_Click(object sender, EventArgs e)
    {

        foreach (DateTime dt in MultipleSelectedDates)
        {
            lblDate.Text = lblDate.Text + " <br/> " + dt.ToString("dd/MM/yyyy");
        }
    }

VB.net Examples :
    Protected Sub Calendar1_PreRender(ByVal sender As Object, ByVal e As EventArgs)

        Calendar1.SelectedDates.Clear()

        For Each dt As DateTime In MultipleSelectedDates
            Calendar1.SelectedDates.Add(dt)
        Next
    End Sub
    Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)

        If MultipleSelectedDates.Contains(Calendar1.SelectedDate) Then
            MultipleSelectedDates.Remove(Calendar1.SelectedDate)
        Else
            MultipleSelectedDates.Add(Calendar1.SelectedDate)
        End If

        ViewState("MultipleSelectedDates") = MultipleSelectedDates
    End Sub


    Public Property MultipleSelectedDates() As List(Of DateTime)
        Get
            If ViewState("MultipleSelectedDates") Is Nothing Then

                ViewState("MultipleSelectedDates") = New List(Of DateTime)()
            End If
            Return DirectCast(ViewState("MultipleSelectedDates"), List(Of DateTime))
        End Get
        Set(ByVal value As List(Of DateTime))
            ViewState("MultipleSelectedDates") = value
        End Set
    End Property

    Protected Sub btnGetSelectedDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetSelectedDate.Click
        For Each dt As DateTime In MultipleSelectedDates
            lblDate.Text = lblDate.Text + " <br/> " & dt.ToString("dd/MM/yyyy")
        Next
    End Sub

Output : 


Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.


Wednesday, 19 September 2012

You can get the selected date from calendar control.
There is a "SelectedDate" property of calendar control. This property is get and set property so you can also set date of calendar control. Calender control provided in asp.net.

Here is example for this.
In this example we take calendar control , button and label. First you select date in control. By Default today date is highlighted but not selected. When you select date at that time date background color will changed after that On click of button we retrieve selected date from calendar control and display in label.
We can also format the date and display in our specific date format. in this example we display date in "dd/MM/yyyy" format.

ASPX Code :
        <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" 
            BorderColor="#FFCC66" DayNameFormat="Shortest" Font-Names="Verdana" 
            Font-Size="8pt" ForeColor="#663399" Height="200px" Width="220px" 
            BorderWidth="1px" ShowGridLines="True">
            <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
            <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
            <OtherMonthDayStyle ForeColor="#CC9966" />
            <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
            <SelectorStyle BackColor="#FFCC66" />
            <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" 
                ForeColor="#FFFFCC" />
            <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
        </asp:Calendar>

         <br />

         <asp:Button runat="server" ID="btnGetSelectedDate" Text="Get Selected Date" 
            onclick="btnGetSelectedDate_Click" /> &nbsp;&nbsp;&nbsp;
         <b>Date : </b><asp:Label runat="server" ID="lblDate" ></asp:Label>

C# Examples :
    protected void btnGetSelectedDate_Click(object sender, EventArgs e)
    {
        lblDate.Text = Calendar1.SelectedDate.Date.ToString("dd/MM/yyyy");
    }

VB.net Examples :
    Protected Sub btnGetSelectedDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetSelectedDate.Click
        lblDate.Text = Calendar1.SelectedDate.Date.ToString("dd/MM/yyyy")
    End Sub

Output : 


For Beginning .Net articles. Click Here...

This type of .Net Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.




Calendar control is available in asp.net.
You can set "asp:Calendar" control on page and set it's various properties.

Here is example for this.
In this example we put calendar control and set it's properties.

ASPX Code :
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
            BorderColor="Black" DayNameFormat="Shortest" Font-Names="Times New Roman" 
            Font-Size="10pt" ForeColor="Black" Height="220px" NextPrevFormat="FullMonth" 
            TitleFormat="Month" Width="400px">
            <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" 
                ForeColor="#333333" Height="10pt" />
            <DayStyle Width="14%" />
            <NextPrevStyle Font-Size="8pt" ForeColor="White" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <SelectedDayStyle BackColor="#CC3333" ForeColor="White" />
            <SelectorStyle BackColor="#CCCCCC" Font-Bold="True" Font-Names="Verdana" 
                Font-Size="8pt" ForeColor="#333333" Width="1%" />
            <TitleStyle BackColor="Black" Font-Bold="True" Font-Size="13pt" 
                ForeColor="White" Height="14pt" />
            <TodayDayStyle BackColor="#CCCC99" />
        </asp:Calendar>

Output :

For Beginning .Net articles. Click Here...

This type of .Net Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



Tuesday, 18 September 2012

 Click Here to Download Sample StickyJavascriptMenu.zip

Now a days sticky menu is most popular menu in websites.
You can generate sticky menu using JQuery and some CSS classes.
You are able to working menu in out downloadable samples.
In this example we integrate sticky menu into aspx page.

Here is example for this.
In this example we are using "jquery-1.4.1.js" JQuery file. You can find this file from JQuery website or in our sample application folder. We are displaying menu on screen and when user scoll down the page our sticky menu is stick at the top of the browser.
You can set many position using javascript and css classes.

ASPX Code :
    <div id="wrapper">
        <header>
        <h1>Simple Sticky Menu</h1>
        </header>
        <nav>
        <table><tr><td>Home</td><td>|</td><td>About Us</td><td>|</td><td>Contact Us</td></tr></table>
        </nav>
        <div id="content">
            Website informations. Website informations. Website informations. Website informations.
            Website informations. Website informations. Website informations. Website informations.
            Website informations.
        </div>
    </div>

Javascript Code :
  $(document).ready(function () {

            var intAboveHeight = $('header').outerHeight();
                    
            $(window).scroll(function () {
                    
                if ($(window).scrollTop() > intAboveHeight) {
                        
                    $('nav').addClass('fixed').css('top', '0').next().css('padding-top', '60px');

                } else {
                        
                    $('nav').removeClass('fixed').next().css('padding-top', '0');
                }
            });
        });

CSS classes :
        #wrapper
        {
            width: 940px;
            margin: 0 auto;
        }
        
        header
        {
            text-align: center;
            padding: 70px 0;
        }
        
        nav
        {
            background: url(bg.png) no-repeat;
            height: 60px;
            width: 960px;
            margin-left: -10px;
            line-height: 50px;
            position: relative;
        }
        
        #content
        {
            background: #fff;
            height: 1500px; /* presetting the height */
            box-shadow: 0 0 5px rgba(0,0,0,0.3);
        }
        
        .fixed
        {
            position: fixed;
        }

Output : 

(To view original image , click on image)

For Beginning .Net articles. Click Here...

This type of .Net Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.




Saturday, 15 September 2012

Alternate text for Image is helpful when certain reason Image is not displayed in browser. If Image is not displayed at that time alternate text is helpful to end user.
Alternate text display instead of image and end use know that here is image and this image is for what.
For that you need to set "alt" property of "Img" tag.

Here is example for this.
In this example we take one html image tag and set it's alternate text and we provide image source file name that does not exist.

ASPX Code : 

      Image : <img src="ttt.png"  alt="Click hete to know more." width="100" height="50" />

Output : 

For Beginning .Net articles. Click Here...

This type of .Net Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.




Friday, 14 September 2012

There is a situation where you want to select an item from drop down list or combo box and raise server side event to do some processing at server side. You can raise or fire server side event on selection of item from drop down list or combo box. It will raise "onselectedindexchanged" event.
For that you need to set AutoPostBack="true" property.

Here is example for this.
In this example we take on product drop down list and select an item from that after item selected dropdonwlist's "onselectedindexchanged" event raised.

ASPX Code :
   <b>Product List :</b>  <asp:DropDownList runat="server" ID="ddlProductList" AutoPostBack="true"
                            onselectedindexchanged="ddlProductList_SelectedIndexChanged"></asp:DropDownList>

C# Examples :
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            ddlProductList.Items.Add(new ListItem("[select]", "-1"));
            ddlProductList.Items.Add(new ListItem("CPU", "1"));
            ddlProductList.Items.Add(new ListItem("LCD", "2"));
            ddlProductList.Items.Add(new ListItem("LED", "3"));
        }
    }

    protected void ddlProductList_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Write("Selected Value : " + ddlProductList.SelectedValue);
        Response.Write("</br>Selected Text : " + ddlProductList.SelectedItem.Text);
        Response.Write("</br></br></br>");
    }

VB.net Example :
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            ddlProductList.Items.Add(New ListItem("[select]", "-1"))
            ddlProductList.Items.Add(New ListItem("CPU", "1"))
            ddlProductList.Items.Add(New ListItem("LCD", "2"))
            ddlProductList.Items.Add(New ListItem("LED", "3"))
        End If
    End Sub

    Protected Sub ddlProductList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Response.Write("Selected Value : " & ddlProductList.SelectedValue)
        Response.Write("</br>Selected Text : " & ddlProductList.SelectedItem.Text)
        Response.Write("</br></br></br>")
    End Sub

Output :


For Beginning .Net articles. Click Here...

This type of .Net Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.