1. Select web project right click and select properties.
2. Select Silverlgiht Application tab
3. Select your Silverlight Application from the list (in this case only one available)
4. Select Add
5. From the next dialogue select check add a test page option (recommended not mandatory) and then click on Add
Saturday, July 17, 2010
Tuesday, July 13, 2010
How to change the Assembly Name and Default Namespace of an asp.net Web-Application - Asp.net, Visual Studio
1.Rightclick on the Web-Applicaiton
2.Select Application Tab and Specify Default Namespace and Assembly Name at the very top of the page
2.Select Application Tab and Specify Default Namespace and Assembly Name at the very top of the page
Monday, July 12, 2010
How to change the status code of the Page Not Found page to 404 - Asp.net
public partial class PageNotFound : System.Web.UI.Page { protected override void OnInit(EventArgs e) { base.OnInit(e); Response.Buffer = true; Response.StatusCode = 404; Response.Status = "404 Not Found"; } }
Saturday, July 10, 2010
How to implement date range validator - Asp.net
<%@ Page Language="C#" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <div> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:TextBox ID="Txtfrom" runat="server" CssClass="dataField" Width="120px"></asp:TextBox> <asp:calendarextender id="Txtfrom_CalendarExtender" runat="server" enabled="True" targetcontrolid="Txtfrom" cleartime="True" todaysdateformat="dd/MM/yyyy" format="dd/MM/yyyy" /> <asp:TextBox ID="Txtto" runat="server" CssClass="dataField" /> <asp:calendarextender id="Txtto_CalendarExtender" runat="server" enabled="True" targetcontrolid="Txtto" format="dd/MM/yyyy" todaysdateformat="dd/MM/yyyy" /> <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToCompare="Txtfrom" ControlToValidate="Txtto" ErrorMessage="from date should not greater then to date" Operator="GreaterThan" Type="Date" /> <asp:Button runat="server" ID="btnPostback" Text="Postback" /> </div> </form> </body> </html>
How to bulid a simple cascade dropdownlist - Asp.net
<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script runat="server"> protected void SelectSubCategoies(object sender, EventArgs e) { string s = this.ddlCategories.SelectedValue; this.ddlSubcategories.Items.Clear(); if (s.Equals("-1")) this.ddlSubcategories.Enabled = false; else { this.ddlSubcategories.Enabled = true; for (int i = 0; i < 10; i++) this.ddlSubcategories.Items.Add(new ListItem(s + " Sub Cateogry")); } } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel runat="server" ID="upnlCascadeDropdown"> <ContentTemplate> <asp:DropDownList runat="server" ID="ddlCategories" AutoPostBack="true" OnSelectedIndexChanged="SelectSubCategoies"> <asp:ListItem Value="-1">Select</asp:ListItem> <asp:ListItem Value="A">Category A</asp:ListItem> <asp:ListItem Value="B">Category B</asp:ListItem> <asp:ListItem Value="C">Category C</asp:ListItem> <asp:ListItem Value="D">Category D</asp:ListItem> </asp:DropDownList> <asp:DropDownList runat="server" ID="ddlSubcategories" Enabled="false"></asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> </form> </body> </html>
How to auto update a segment a page - Asp.net
<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <style type="text/css"> .Hide {display:none; } </style> <script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); ScriptManager.RegisterStartupScript( this, this.GetType(), this.GetType().Name, string.Format("setTimeout(\"__doPostBack('{0}','')\", 5000)", this.btnPostback.UniqueID), true); this.lblUpdatedOn.Text = DateTime.Now.ToString("hh:mm:ss"); } protected void AutoPostback(object sender, EventArgs e) { } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel runat="server" ID="upnlCascadeDropdown"> <ContentTemplate> Last Updated on: <asp:Label runat="server" ID="lblUpdatedOn" /> <asp:Button CssClass="Hide" runat="server" ID="btnPostback" OnClick="AutoPostback" UseSubmitBehavior="false" /> </ContentTemplate> </asp:UpdatePanel> </form> </body> </html>
Tuesday, June 29, 2010
How to find end date of any month in any year - C#
We can use an Enum to find end dates of any month in given year:
public partial class Test : Page { protected override void OnLoad(EventArgs e) { base.OnLoad(e); string[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; for (int y = 1998; y < 2010; y++) { this.Response.Write(y + " = "); foreach (string m in months) { this.Response.Write(m + ": " + Month.GetLastDate(m, y)); this.Response.Write(" - "); } this.Response.Write("<hr />"); } } protected override void OnInit(EventArgs e) { } } public class Month { public enum MonthEndDate { Jan = 31, Feb = 28, Mar = 31, Apr = 30, May = 31, Jun = 30, Jul = 31, Aug = 31, Sep = 30, Oct = 31, Nov = 30, Dec = 31 }; public static int GetLastDate(string month, int year) { MonthEndDate endDate = (MonthEndDate)Enum.Parse(typeof(MonthEndDate), month); int enddate = (int)endDate; if (endDate == MonthEndDate.Feb) if (year % 4 == 0) enddate++; return enddate; } }
How to disable weekends of asp.net calender - Asp.net
We can use following properties to disable days of the asp.net calender.
- e.Cell.Enabled
- e.Day.IsSelectable
- e.Cell.BackColor
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script runat="server"> protected void DayRander(object sender, DayRenderEventArgs e) { if(e.Day.IsWeekend) { e.Cell.Enabled = false; e.Day.IsSelectable = false; e.Cell.BackColor = Color.Gray; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar runat="server" ID="calDates" OnDayRender="DayRander" /> </div> </form> </body> </html>
How to disable day of asp.net calender based on criteria - Asp.net
Inorder to disable perticular date in calender, we can use three properties of day render event arguement.
- e.Cell.Enabled
- e.Day.IsSelectable
- e.Cell.BackColor = Color.Gray
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script runat="server"> List<DateTime> validDays = new List<DateTime>(); protected override void OnLoad(EventArgs e) { validDays = this.FindValidDates(); } private List<DateTime> FindValidDates() { int month = DateTime.Now.Month; int year = DateTime.Now.Year; for (int i = 1; i < 31; i += 2) validDays.Add(new DateTime(year, month, i)); return validDays; } protected void DayRander(object sender, DayRenderEventArgs e) { if (!validDays.Exists(x => x == e.Day.Date)) { e.Cell.Enabled = false; e.Day.IsSelectable = false; e.Cell.BackColor = Color.Gray; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar runat="server" ID="calDates" OnDayRender="DayRander" /> </div> </form> </body> </html>
How to configure directory browsing - II6 / IIS7
How to set up direcotry browsing in IIS 7
1.Open IIS manager - run inetmgr
2.Expand the tree, under [Server Name]/Sites - Click on web site / virtual direcotry required
3.Under IIS section, please click on direcotry bowsing section.
4.On the righthand side please click on Enable/Disable directory browsing option.
How to setup direcotry browsing in IIS6
1.Open IIS manger - run inetmgr
2.Expand the tree, under [Server Name]/Web Sites - right click on web site / virtual directory required.
3.Under Home Directory please check/uncheck Directory Bowsing option
1.Open IIS manager - run inetmgr
2.Expand the tree, under [Server Name]/Sites - Click on web site / virtual direcotry required
3.Under IIS section, please click on direcotry bowsing section.
4.On the righthand side please click on Enable/Disable directory browsing option.
How to setup direcotry browsing in IIS6
1.Open IIS manger - run inetmgr
2.Expand the tree, under [Server Name]/Web Sites - right click on web site / virtual directory required.
3.Under Home Directory please check/uncheck Directory Bowsing option
Monday, June 28, 2010
How to show the progress of long running operation - Simple Example
Demo:
This article demonstrates how to show the progress of a long running operation using simple label text. But you can add a spning progress indicator and make it much fancy.
Screenshots:
Markup:
This article demonstrates how to show the progress of a long running operation using simple label text. But you can add a spning progress indicator and make it much fancy.
Screenshots:
Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="ActiveTest.Test" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <style type="text/css"> .Hide { display:none; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button runat="server" ID="btnDoTask" Text="Do Task" OnClick="Button1_Click" /> <asp:Label runat="server" ID="lblMessage" /> <asp:Button runat="server" ID="btnHidden" UseSubmitBehavior="false" CssClass="Hide" /> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>Code behind:
public partial class Test : Page { private string script = @"setTimeout(""__doPostBack('{0}','')"", 5000);"; public bool Processing { get { return (bool)(Session["Processing"] ?? false); } set { Session["Processing"] = value; } } public bool Completed { get { return (bool)(Session["Completed"] ?? (Session["Completed"] = true)); } set { Session["Completed"] = value; } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.Processing) { this.lblMessage.Text = "Processing... Please wait..."; ScriptManager.RegisterStartupScript(this, this.GetType(), this.GetType().Name, string.Format(script, this.btnHidden.ClientID), true); } else { if (!this.Completed) { lblMessage.Text = "Processing is complete"; this.Completed = true; } else lblMessage.Text = string.Empty; } } protected void Button1_Click(object sender, EventArgs e) { Thread thread = new Thread(new ThreadStart(SomeLongOperation)); thread.Start(); this.lblMessage.Text = "Processing... Please wait..."; this.Processing = true; ScriptManager.RegisterStartupScript(this, this.GetType(), this.GetType().Name, string.Format(script, this.btnHidden.ClientID), true); } void SomeLongOperation() { this.Completed = false; for (int i = 0; i < 20; i++) Thread.Sleep(1000); this.Processing = false; } }
Subscribe to:
Posts (Atom)
Azure Storage Account Types
Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...
-
Demo: I was thinking a way to show images before actually uploading them to server. I would say to preview images using javascript. Obv...
-
Demo : I am using asp.net UpdatePanel control to partial page update. As there is no keyup event for the asp.net TextBox control, I add an ...












