Tuesday, 29 July 2014

c# example – Datetime Days in month

Sometimes we need to know programmatically that how many days exists in current month from a date time object. or how many days exists in any specific month. we are know that in july there are 31 days and in june there are 30 days. but how can we get it by .net programming? there is a simple solution. here we usees a date time function method name DaysInMonth. pass the two argument year and month number. it will output the exact days number.
datetime-days-in-month.aspx :
  1. <%@ Page Language=“C#” AutoEventWireup=“true”%>

  2. <!DOCTYPE html>
  3. <script runat=“server”>
  4.     protected void Button1_Click(object sender, System.EventArgs e)
  5.     {
  6.         //initialize a datetime variable with today
  7.         DateTime today = DateTime.Today;

  8.         //get number of days in current month
  9.         int numberOfDays = DateTime.DaysInMonth(today.Year,today.Month);

  10.         Label1.Text = “today : “ + today.ToLongDateString();

  11.         Label1.Text += “<br /><br />days in current month : “;
  12.         Label1.Text += numberOfDays;
  13.     }
  14. </script>

  15. <html xmlns=“http://www.w3.org/1999/xhtml”>
  16. <head id=“Head1″ runat=“server”>
  17.     <title>c# example - datetime days in month</title>
  18. </head>
  19. <body>
  20.     <form id=“form1″ runat=“server”>
  21.     <div>
  22.         <h2 style=“color:MidnightBlue; font-style:italic;”>
  23.             c# example - datetime days in month
  24.         </h2>
  25.         <hr width=“550″ align=“left” color=“Gainsboro” />
  26.         <asp:Label
  27.             ID=“Label1″
  28.             runat=“server”
  29.             Font-Size=“Large”
  30.             Font-Names=“Comic Sans MS”
  31.             >
  32.         </asp:Label>
  33.         <br /><br />
  34.         <asp:Button
  35.             ID=“Button1″
  36.             runat=“server”
  37.             Text=“get number of days in current month”
  38.             OnClick=“Button1_Click”
  39.             Height=“40″
  40.             Font-Bold=“true”
  41.             />
  42.     </div>
  43.     </form>
  44. </body>
  45. </html>

How to change asp.net Button width programmatically

How to set, change Button width programmatically:
  1. <%@ Page Language=“C#” %>

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

  3. <script runat=“server”>
  4.     protected void Button2_Click(object sender, System.EventArgs e)
  5.     {
  6.          Button1.Width = 200;
  7.     }
  8.     protected void Button3_Click(object sender, System.EventArgs e)
  9.     {
  10.         Button1.Width = 300;
  11.     }
  12. </script>

  13. <html xmlns=“http://www.w3.org/1999/xhtml”>
  14. <head id=“Head1″ runat=“server”>
  15.     <title>How to set, change Button width programmatically</title>
  16. </head>
  17. <body>
  18.     <form id=“form1″ runat=“server”>
  19.     <div>
  20.         <h2 style=“color:Red”>Button Example: Width</h2>
  21.         <asp:Button
  22.              ID=“Button1″
  23.              runat=“server”
  24.              Text=“Test Button Width”
  25.              ForeColor=“SaddleBrown”
  26.              Font-Bold=“true”
  27.              Height=“30″
  28.              />
  29.         <br /><br />
  30.         <asp:Button
  31.              ID=“Button2″
  32.              runat=“server”
  33.              Text=“Button Width 200″
  34.              OnClick=“Button2_Click”
  35.              />
  36.         <asp:Button
  37.              ID=“Button3″
  38.              runat=“server”
  39.              Text=“Button Width 300″
  40.              OnClick=“Button3_Click”
  41.              />
  42.     </div>
  43.     </form>
  44. </body>
  45. </html>



Change Label border color Programmatically in ASP.NET

Change Label border color Programmatically in ASP.NET
  1. <%@ Page Language=“C#” %>

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

  3. <script runat=“server”>
  4.     protected void Button1_Click(object sender, System.EventArgs e)
  5.     {
  6.         Label1.BorderColor = System.Drawing.Color.HotPink;
  7.     }
  8.     protected void Button2_Click(object sender, System.EventArgs e)
  9.     {
  10.         Label1.BorderColor = System.Drawing.Color.SpringGreen;
  11.     }
  12. </script>

  13. <html xmlns=“http://www.w3.org/1999/xhtml”>
  14. <head id=“Head1″ runat=“server”>
  15.     <title>How to set, change Label border color programmatically</title>
  16. </head>
  17. <body>
  18.     <form id=“form1″ runat=“server”>
  19.     <div>
  20.         <h2 style=“color:Navy”>Label Example: BorderColor</h2>
  21.         <asp:Label
  22.              ID=“Label1″
  23.              runat=“server”
  24.              Text=“Click any button for change border color.”
  25.              BorderWidth=“2″
  26.              >
  27.         </asp:Label>
  28.         <br /><br />
  29.         <asp:Button
  30.              ID=“Button1″
  31.              runat=“server”
  32.              ForeColor=“SlateBlue”
  33.              Text=“BorderColor HotPink”
  34.              OnClick=“Button1_Click”
  35.              Font-Bold=“true”
  36.              />
  37.         <asp:Button
  38.              ID=“Button2″
  39.              runat=“server”
  40.              Font-Bold=“true”
  41.              ForeColor=“SlateBlue”
  42.              Text=“BorderColor SpringGreen”
  43.              OnClick=“Button2_Click”
  44.              />
  45.     </div>
  46.     </form>
  47. </body>
  48. </html>



How to use Associated control Id in ASP.NET Label

How to use Associated control Id in ASP.NET Label

  1. <%@ Page Language=“C#” %>

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

  3. <script runat=“server”>

  4. </script>

  5. <html xmlns=“http://www.w3.org/1999/xhtml”>
  6. <head id=“Head1″ runat=“server”>
  7.     <title>How to use associated control id (AssociatedControlID) in Label</title>
  8. </head>
  9. <body>
  10.     <form id=“form1″ runat=“server”>
  11.     <div>
  12.         <h2 style=“color:Navy”>Label Example: AssociatedControlID</h2>
  13.         <asp:Label
  14.              ID=“Label1″
  15.              runat=“server”
  16.              ForeColor=“CadetBlue”
  17.              Text=“<u>U</u>ser Name”
  18.              ToolTip=“Color label”
  19.              AccessKey=“U”
  20.              AssociatedControlID=“TextBox1″
  21.              >
  22.         </asp:Label>
  23.         <asp:TextBox
  24.              ID=“TextBox1″
  25.              runat=“server”
  26.              BackColor=“SeaGreen”
  27.              ForeColor=“AliceBlue”
  28.              >
  29.         </asp:TextBox>
  30.     </div>
  31.     </form>
  32. </body>
  33. </html>


How to use tool tip (ToolTip) in ASP.Net Label

  1. <%@ Page Language=“C#” %>
  2. <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
  3. <script runat=“server”>
  4. </script>
  5. <html xmlns=“http://www.w3.org/1999/xhtml”>
  6. <head id=“Head1″ runat=“server”>
  7.     <title>How to use tool tip (ToolTip) in Label</title>
  8. </head>
  9. <body>
  10.     <form id=“form1″ runat=“server”>
  11.     <div>
  12.         <h2 style=“color:Navy”>Label Example: ToolTip</h2>
  13.         <asp:Label
  14.              ID=“Label1″
  15.              runat=“server”
  16.              ForeColor=“OrangeRed”
  17.              BackColor=“LightCyan”
  18.              Font-Size=“X-Large”
  19.              Text=“DodgerBlue”
  20.              ToolTip=“Color label”
  21.              >
  22.         </asp:Label>
  23.         <br /><br />
  24.         <asp:Label
  25.              ID=“Label2″
  26.              runat=“server”
  27.              ForeColor=“Snow”
  28.              BackColor=“DarkCyan”
  29.              Font-Size=“X-Large”
  30.              Text=“XmlDataSource”
  31.              ToolTip=“asp.net control”
  32.              >
  33.         </asp:Label>
  34.     </div>
  35.     </form>
  36. </body>
  37. </html>




How to use theme and skin in ASP.NET Label

How to use theme and skin in ASP.NET Label
  1. <%@ Page Language=“C#” Theme=“Blue” %>

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

  3. <script runat=“server”>

  4. </script>

  5. <html xmlns=“http://www.w3.org/1999/xhtml”>
  6. <head id=“Head1″ runat=“server”>
  7.     <title>How to use theme and skin in Label</title>
  8. </head>
  9. <body>
  10.     <form id=“form1″ runat=“server”>
  11.     <div>
  12.         <h2 style=“color:Red”>Label Example: Theme</h2>
  13.         <asp:Label
  14.              ID=“Label1″
  15.              runat=“server”
  16.              Text=“This Label using theme.”
  17.              BackColor=“DarkGreen”
  18.              ForeColor=“FloralWhite”
  19.              Font-Size=“X-Large”
  20.              Font-Italic=“true”
  21.              BorderColor=“LawnGreen”
  22.              BorderWidth=“2″
  23.              >
  24.         </asp:Label>
  25.     </div>
  26.     </form>
  27. </body>
  28. </html>


How to hide visible ASP.NET CheckBox Programmatically

How to hide visible ASP.NET CheckBox Programmatically

  1. <%@ Page Language=“C#” %>

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

  3. <script runat=“server”>
  4.     protected void Button1_Click(object sender, System.EventArgs e)
  5.     {
  6.         CheckBox1.Visible = false;
  7.         Label1.Text = “CheckBox Hide.”;
  8.     }
  9.     protected void Button2_Click(object sender, System.EventArgs e)
  10.     {
  11.         CheckBox1.Visible = true;
  12.         Label1.Text = “CheckBox Visible.”;
  13.     }
  14. </script>

  15. <html xmlns=“http://www.w3.org/1999/xhtml”>
  16. <head id=“Head1″ runat=“server”>
  17.     <title>How to hide, visible CheckBox programmatically</title>
  18. </head>
  19. <body>
  20.     <form id=“form1″ runat=“server”>
  21.     <div>
  22.         <h2 style=“color:Green”>asp.net CheckBox example: Hide, Visible</h2>
  23.         <asp:Label
  24.              ID=“Label1″
  25.              runat=“server”
  26.              Font-Size=“Large”
  27.              ForeColor=“Violet”
  28.              >
  29.         </asp:Label>
  30.         <br /><br />
  31.         <asp:CheckBox
  32.              ID=“CheckBox1″
  33.              runat=“server”
  34.              Text=“Check The CheckBox.”
  35.              AutoPostBack=“false”
  36.              ForeColor=“Tomato”
  37.              />
  38.         <br /><br />
  39.         <asp:Button
  40.              ID=“Button1″
  41.              runat=“server”
  42.              ForeColor=“Violet”
  43.              Text=“Hide CheckBox”
  44.              OnClick=“Button1_Click”
  45.              Font-Bold=“true”
  46.              />
  47.         <asp:Button
  48.              ID=“Button2″
  49.              runat=“server”
  50.              Font-Bold=“true”
  51.              ForeColor=“Violet”
  52.              Text=“Visible CheckBox”
  53.              OnClick=“Button2_Click”
  54.              />
  55.     </div>
  56.     </form>
  57. </body>
  58. </html>