Archive

Archive for May, 2011

Show MessageBox Message with UpdatePanel

May 29, 2011 7 comments

Hi all try this example to show MessageBox with UpdatePanel

1) Creat Class called MessageBox.cs


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for MessageBox
/// </summary>
public class MessageBox
{
#region Constructor
public MessageBox()
{
//
// TODO: Add constructor logic here
//
}
#endregion
#region Void
public static void Show(UpdatePanel updatepanel, string message)
{
ScriptManager.RegisterStartupScript(updatepanel, updatepanel.GetType(), "MessageBox", "alert('" + message + "')", true);
}
public static void Show(Page page, string message)
{
ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "MessageBox", "alert('" + message + "')", true);
}
#endregion
}

and to use it

MessageBox.Show(this,"Welcome to my blog");

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Javascript

Get Date of Days between two Date

Hi all,

try this example to Get Date of Days between two Date

1) Create a website and add new web page


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table style="width:50%;">
        <tr>
            <td>
                From date :-
            </td>
            <td>
                <asp:TextBox ID="txt_FromDate" runat="server"></asp:TextBox>
                <cc1:CalendarExtender ID="txt_FromDate_CalendarExtender" runat="server"
                    Enabled="True" TargetControlID="txt_FromDate">
                </cc1:CalendarExtender>
            </td>
            <td>
               To date :-
            </td>
            <td>
                <asp:TextBox ID="txt_ToDate" runat="server"></asp:TextBox>
                <cc1:CalendarExtender ID="txt_ToDate_CalendarExtender" runat="server"
                    Enabled="True" TargetControlID="txt_ToDate">
                </cc1:CalendarExtender>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <asp:CheckBoxList ID="cbl_Days" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem>Saturday
                    </asp:ListItem>
                    <asp:ListItem>Sunday
                    </asp:ListItem>
                    <asp:ListItem>Monday
                    </asp:ListItem>
                    <asp:ListItem>Tuesday
                    </asp:ListItem>
                    <asp:ListItem>Wednesday
                    </asp:ListItem>
                    <asp:ListItem>Thursday
                    </asp:ListItem>
                    <asp:ListItem>Friday
                    </asp:ListItem>
                </asp:CheckBoxList>
            </td>
        </tr>
        <tr>
            <td colspan="4" align="center">
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
                Text="Get Data" />
            </td>
        </tr>
    </table>
    </form>
    </body>
</html>

and in code behind :-

protected void Button1_Click(object sender, EventArgs e)
    {
        //DateTime dFrom = new DateTime(2011, 1, 1);
        //DateTime dTo = new DateTime(2011, 1, 10);
        DateTime dFrom = DateTime.Parse(txt_FromDate.Text);
        DateTime dTo = DateTime.Parse(txt_ToDate.Text);
        //int diff = (dTo - dFrom).Days;
        TimeSpan DateDiff = dTo.Subtract(dFrom);
        for (int i = 0; i < DateDiff.Days; i++)
        {
            foreach (ListItem item in cbl_Days.Items)
            {
                if (item.Selected)
                {
                    if (dFrom.AddDays(i).DayOfWeek.ToString().ToLower() == item.Text.Trim().ToLower())
                    {
                        Response.Write(dFrom.Date.AddDays(i).ToString("MM/dd/yyyy")+" "+dFrom.Date.AddDays(i).DayOfWeek+"</br>");
                    }
                }
            }
        }
    }

Hope this helps

Good Luck

Categories: ASP.Net

News Slider using JQuery

Hi all,

Try this Example to make News Slider using JQuery


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
    <script src="http://bxslider.com/js/jquery.bxSlider.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://bxslider.com/bx_styles/bx_styles.css" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function() {
            $(document).ready(function() {
                $('#slider1').bxSlider({
                    auto: true,
                    autoControls: true,
                    autoHover: true,
                    pager: false,
                    controls: false
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Repeater ID="rptNews" runat="server">
        <HeaderTemplate>
            <ul id="slider1">
        </HeaderTemplate>
        <ItemTemplate>
            <li>
                <img src='<%#Eval("Image")%>' width="219" height="218" />
                <h3>
                    <%#Eval("Title")%><span><%#Eval("Year")%></span></h3>
                <p>
                   <%#Eval("Content")%> </p>
                <div>
                </div>
            </li>
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
    </form>
</body>
</html>

and in code behind :-


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var list = (new[]{
            new{
                Title="led zeppelin I",
                Year="1968", 
                Content="the conceptual originality of the album was displayed on tracks such as \"good times bad times\", \"dazed and confused\" and \"communication breakdown\", which had a distinctively heavy sound to the ears of young rock fans in the late-1960s.", 
                Image="http://bxslider.com/images/pic_zep1.jpg"
               },
            new{
                Title="led zeppelin II",
                Year="169", 
                Content="led zeppelin II furthered the lyrical themes established on their debut album, creating a work that became more widely acclaimed and influential than its predecessor. with elements of blues and folk music, it also exhibits the band's evolving musical style of blues-derived material and their guitar and riff-based sound. it is one of the band's heaviest albums.", 
                Image="http://bxslider.com/images/pic_zep2.jpg"
               },
            new{
                Title="led zeppelin III",
                Year="1970", 
                Content="composed largely at a remote cottage in wales known as Bron-Yr-Aur, this work represented a maturing of the band's music towards a greater emphasis on folk and acoustic sounds. this surprised many fans and critics, and upon its release the album received rather indifferent reviews.", 
                Image="http://bxslider.com/images/pic_zep3.jpg"
               },
            new{
                Title="led zeppelin IV (zoso)",
                Year="1971", 
                Content="no title is printed on the album, so it is generally referred to as led zeppelin IV, following the naming standard used by the band's first three studio albums. also the album has alternatively been referred to as zoso.", 
                Image="http://bxslider.com/images/pic_zep4.jpg"
               }
           
        }).ToList();
            rptNews.DataSource = list;
            rptNews.DataBind();
        }
    }
}

Hope this helps

Good Luck

Categories: ASP.Net, Jquery