Saturday, 28 June 2014
Wednesday, 30 October 2013
How to Close Fancybox and Redirect to another page in asp.net and C#.
Just need to use the code.
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "add", "window.top.location.href ='" +RedirectUrl+ "'; parent.jQuery.fancybox.close();", true);
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "add", "window.top.location.href ='" +RedirectUrl+ "'; parent.jQuery.fancybox.close();", true);
Sunday, 6 October 2013
how to trim text box value in javascript in .Net
// implementing a trim function for strings in javascript
<script language="JavaScript" type="text/javascript">
<!--
String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
</script>
<asp:TextBox runat="server" ID="abdc" onkeyup ="OnChange(this)" onblur="ShowAvailability()" onchange="this.value=this.value.trim()"></asp:TextBox>
<script language="JavaScript" type="text/javascript">
<!--
String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
</script>
<asp:TextBox runat="server" ID="abdc" onkeyup ="OnChange(this)" onblur="ShowAvailability()" onchange="this.value=this.value.trim()"></asp:TextBox>
Friday, 4 October 2013
Date and Time formats in asp.net using C#,VB.Net | Convert date time formats
Date and Time formats in asp.net using C#,VB.Net | Convert date time formats
Introduction: In this article i am going to explain with example list of different date and time formats/types available in asp.net using both C# and VB.Net language.
Description: In previous related articles i explained How to Get age in years,months,days,hours and seconds from DOB in asp.net C#,Vb.Net and Formatting Date in GridView and Get current date in dd/mm/yyyy format and Date format in sql server and How to Convert Rupees,Currency or Numbers to Words.
It is very common in asp.net application or any other application to show date and time in various formats as per application requirement. There are so many different datetime formats/type available that can be used as per application requirement.Some of them are custom date and time formats. So this example will be helpful for those who are searching for datetime formatting and converting date and time format to one format to another e.g. dd/MM/yyyy to MM/dd/yyyy and in any other.
Implementation: Let's see the different formats with example.I have listed many date time formats that will be useful for developers.
C#.Net Code to show/display list of different Date and Time formats
Description: In previous related articles i explained How to Get age in years,months,days,hours and seconds from DOB in asp.net C#,Vb.Net and Formatting Date in GridView and Get current date in dd/mm/yyyy format and Date format in sql server and How to Convert Rupees,Currency or Numbers to Words.
It is very common in asp.net application or any other application to show date and time in various formats as per application requirement. There are so many different datetime formats/type available that can be used as per application requirement.Some of them are custom date and time formats. So this example will be helpful for those who are searching for datetime formatting and converting date and time format to one format to another e.g. dd/MM/yyyy to MM/dd/yyyy and in any other.
Implementation: Let's see the different formats with example.I have listed many date time formats that will be useful for developers.
C#.Net Code to show/display list of different Date and Time formats
protected void btnDateTime_Click(object sender, EventArgs e)
{
Response.Write("<BR>" + DateTime.Today.ToString("dd-MM-yyyy")); // Output : 14-08-2013
Response.Write("<BR>" + DateTime.Today.ToString("dd/MM/yyyy")); // Output : 14/08/2013
Response.Write("<BR>" + DateTime.Today.ToString("dd MM yyyy")); // Output : 14 08 2013
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("dd-MM-yy")); // Output : 14-08-13
Response.Write("<BR>" + DateTime.Today.ToString("dd/MM/yy")); // Output : 14/08/13
Response.Write("<BR>" + DateTime.Today.ToString("dd MM yy")); // Output : 14 08 13
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("ddd-dd-MM-yy")); // Output : Wed-14-08-13
Response.Write("<BR>" + DateTime.Today.ToString("ddd/dd/MM/yy")); // Output : Wed/14/08/13
Response.Write("<BR>" + DateTime.Today.ToString("ddd dd MM yy")); // Output : Wed 14 08 13
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("dddd-dd-MM-yy")); // Output : Wednesday-14-08-13
Response.Write("<BR>" + DateTime.Today.ToString("dddd/dd/MM/yy")); // Output : Wednesday/14/08/13
Response.Write("<BR>" + DateTime.Today.ToString("dddd dd MM yy")); // Output : Wednesday 14 08 13
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("dd-MMM-yyyy")); // Output : 14-Aug-2013
Response.Write("<BR>" + DateTime.Today.ToString("dd/MMM/yyyy")); // Output : 14/Aug/2013
Response.Write("<BR>" + DateTime.Today.ToString("dd MMM yyyy")); // Output : 14 Aug 2013
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("dd-MMMM-yyyy")); // Output : 14-August-2013
Response.Write("<BR>" + DateTime.Today.ToString("dd/MMMM/yyyy")); // Output : 14/August/2013
Response.Write("<BR>" + DateTime.Today.ToString("dd MMMM yyyy")); // Output : 14 August 2013
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("MM-dd-yyyy")); // Output : 08-14-2013
Response.Write("<BR>" + DateTime.Today.ToString("MM/dd/yyyy")); // Output : 08/14/2013
Response.Write("<BR>" + DateTime.Today.ToString("MM dd yyyy")); // Output : 08 14 2013
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("MMM-dd-yyyy")); // Output : Aug-14-2013
Response.Write("<BR>" + DateTime.Today.ToString("MMM/dd/yyyy")); // Output : Aug/14/2013
Response.Write("<BR>" + DateTime.Today.ToString("MMM dd yyyy")); // Output : Aug 14 2013
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Today.ToString("yyyy-MM-dd")); // Output : 2013-08-14
Response.Write("<BR>" + DateTime.Today.ToString("yyyy/MM/dd")); // Output : 2013/08/14
Response.Write("<BR>" + DateTime.Today.ToString("yyyy MM dd")); // Output : 2013 08 14
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Now.ToString("yyyy-MM-dd h:m:s")); // Output : 2013-08-14 5:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy/MM/dd h:m:s")); // Output : 2013/08/14 5:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy MM dd h:m:s")); // Output : 2013 08 14 5:12:30
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); // Output : 2013-08-14 05:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")); // Output : 2013/08/14 05:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy MM dd hh:mm:ss")); // Output : 2013 08 14 05:12:30
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Now.ToString("yyyy-MM-dd H:m:s")); // Output : 2013-08-14 17:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy/MM/dd H:m:s")); // Output : 2013/08/14 17:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy MM dd H:m:s")); // Output : 2013 08 14 17:12:30
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // Output : 2013-08-14 17:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); // Output : 2013/08/14 17:12:30
Response.Write("<BR>" + DateTime.Now.ToString("yyyy MM dd HH:mm:ss")); // Output : 2013 08 14 17:12:30
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt")); // Output : 2013-08-14 17:12:30 PM
Response.Write("<BR>" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt")); // Output : 2013/08/14 17:12:30 PM
Response.Write("<BR>" + DateTime.Now.ToString("yyyy MM dd HH:mm:ss tt")); // Output : 2013 08 14 17:12:30 PM
Response.Write("<BR/>" + "------------------------");
DateTime now = DateTime.Now;
Response.Write("<BR/>" + now.ToString("d")); // Output : 14-Aug-13
Response.Write("<BR/>" + now.ToString("D")); // Output : Wednesday, August 14, 2013
Response.Write("<BR/>" + now.ToString("f")); // Output : Wednesday, August 14, 2013 5:12 PM
Response.Write("<BR/>" + now.ToString("F")); // Output : Wednesday, August 14, 2013 5:12:30 PM
Response.Write("<BR/>" + now.ToString("g")); // Output : 14-Aug-13 5:12 PM
Response.Write("<BR/>" + now.ToString("G")); // Output : 14-Aug-13 5:12:30 PM
Response.Write("<BR/>" + now.ToString("m")); // Output : August 14
Response.Write("<BR/>" + now.ToString("M")); // Output : August 14
Response.Write("<BR/>" + now.ToString("o")); // Output : 2013-08-14T17:12:30.1324811+05:30
Response.Write("<BR/>" + now.ToString("O")); // Output : 2013-08-14T17:12:30.1324811+05:30
Response.Write("<BR/>" + now.ToString("s")); // Output : 2013-08-14T17:12:30
Response.Write("<BR/>" + now.ToString("t")); // Output : 5:12 PM
Response.Write("<BR/>" + now.ToString("T")); // Output : 5:12:30 PM
Response.Write("<BR/>" + now.ToString("u")); // Output : 2013-08-14 17:12:30Z
Response.Write("<BR/>" + now.ToString("U")); // Output : Wednesday, August 14, 2013 11:42:30 AM
Response.Write("<BR/>" + now.ToString("y")); // Output : August, 2013
Response.Write("<BR/>" + now.ToString("Y")); // Output : August, 2013
Response.Write("<BR/>" + "------------------------");
Response.Write("<BR/>" + now.ToLongDateString()); // Output : Wednesday, August 14, 2013
Response.Write("<BR/>" + now.ToLongTimeString()); // Output : 5:12:30 PM
Response.Write("<BR/>" + now.ToShortDateString()); // Output : 14-Aug-13
Response.Write("<BR/>" + now.ToShortTimeString()); // Output : 5:12 PM
Response.Write("<BR/>" + now.ToString()); // Output : 14-Aug-13 5:12:30 PM
}
VB.Net Code to show/display list of different Date and Time formats
Protected Sub btnDateTime_Click(sender As Object, e As System.EventArgs) HandlesbtnDateTime.Click
Response.Write("<BR>" & DateTime.Today.ToString("dd-MM-yyyy")) ' Output : 14-08-2013
Response.Write("<BR>" & DateTime.Today.ToString("dd/MM/yyyy")) ' Output : 14/08/2013
Response.Write("<BR>" & DateTime.Today.ToString("dd MM yyyy")) ' Output : 14 08 2013
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("dd-MM-yy")) ' Output : 14-08-13
Response.Write("<BR>" & DateTime.Today.ToString("dd/MM/yy")) ' Output : 14/08/13
Response.Write("<BR>" & DateTime.Today.ToString("dd MM yy")) ' Output : 14 08 13
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("ddd-dd-MM-yy")) ' Output : Wed-14-08-13
Response.Write("<BR>" & DateTime.Today.ToString("ddd/dd/MM/yy")) ' Output : Wed/14/08/13
Response.Write("<BR>" & DateTime.Today.ToString("ddd dd MM yy")) ' Output : Wed 14 08 13
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("dddd-dd-MM-yy")) ' Output : Wednesday-14-08-13
Response.Write("<BR>" & DateTime.Today.ToString("dddd/dd/MM/yy")) ' Output : Wednesday/14/08/13
Response.Write("<BR>" & DateTime.Today.ToString("dddd dd MM yy")) ' Output : Wednesday 14 08 13
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("dd-MMM-yyyy")) ' Output : 14-Aug-2013
Response.Write("<BR>" & DateTime.Today.ToString("dd/MMM/yyyy")) ' Output : 14/Aug/2013
Response.Write("<BR>" & DateTime.Today.ToString("dd MMM yyyy")) ' Output : 14 Aug 2013
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("dd-MMMM-yyyy")) ' Output : 14-August-2013
Response.Write("<BR>" & DateTime.Today.ToString("dd/MMMM/yyyy")) ' Output : 14/August/2013
Response.Write("<BR>" & DateTime.Today.ToString("dd MMMM yyyy")) ' Output : 14 August 2013
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("MM-dd-yyyy")) ' Output : 08-14-2013
Response.Write("<BR>" & DateTime.Today.ToString("MM/dd/yyyy")) ' Output : 08/14/2013
Response.Write("<BR>" & DateTime.Today.ToString("MM dd yyyy")) ' Output : 08 14 2013
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("MMM-dd-yyyy")) ' Output : Aug-14-2013
Response.Write("<BR>" & DateTime.Today.ToString("MMM/dd/yyyy")) ' Output : Aug/14/2013
Response.Write("<BR>" & DateTime.Today.ToString("MMM dd yyyy")) ' Output : Aug 14 2013
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Today.ToString("yyyy-MM-dd")) ' Output : 2013-08-14
Response.Write("<BR>" & DateTime.Today.ToString("yyyy/MM/dd")) ' Output : 2013/08/14
Response.Write("<BR>" & DateTime.Today.ToString("yyyy MM dd")) ' Output : 2013 08 14
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Now.ToString("yyyy-MM-dd h:m:s")) ' Output : 2013-08-14 5:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy/MM/dd h:m:s")) ' Output : 2013/08/14 5:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy MM dd h:m:s")) ' Output : 2013 08 14 5:12:30
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")) ' Output : 2013-08-14 05:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")) ' Output : 2013/08/14 05:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy MM dd hh:mm:ss")) ' Output : 2013 08 14 05:12:30
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Now.ToString("yyyy-MM-dd H:m:s")) ' Output : 2013-08-14 17:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy/MM/dd H:m:s")) ' Output : 2013/08/14 17:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy MM dd H:m:s")) ' Output : 2013 08 14 17:12:30
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) ' Output : 2013-08-14 17:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")) ' Output : 2013/08/14 17:12:30
Response.Write("<BR>" & DateTime.Now.ToString("yyyy MM dd HH:mm:ss")) ' Output : 2013 08 14 17:12:30
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR>" & DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt")) ' Output : 2013-08-14 17:12:30 PM
Response.Write("<BR>" & DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss tt")) ' Output : 2013/08/14 17:12:30 PM
Response.Write("<BR>" & DateTime.Now.ToString("yyyy MM dd HH:mm:ss tt")) ' Output : 2013 08 14 17:12:30 PM
Response.Write("<BR/>" & "------------------------")
Dim now As DateTime = DateTime.Now
Response.Write("<BR/>" & now.ToString("d")) ' Output : 14-Aug-13
Response.Write("<BR/>" & now.ToString("D")) ' Output : Wednesday, August 14, 2013
Response.Write("<BR/>" & now.ToString("f")) ' Output : Wednesday, August 14, 2013 5:12 PM
Response.Write("<BR/>" & now.ToString("F")) ' Output : Wednesday, August 14, 2013 5:12:30 PM
Response.Write("<BR/>" & now.ToString("g")) ' Output : 14-Aug-13 5:12 PM
Response.Write("<BR/>" & now.ToString("G")) ' Output : 14-Aug-13 5:12:30 PM
Response.Write("<BR/>" & now.ToString("m")) ' Output : August 14
Response.Write("<BR/>" & now.ToString("M")) ' Output : August 14
Response.Write("<BR/>" & now.ToString("o")) ' Output : 2013-08-14T17:12:30.1324811+05:30
Response.Write("<BR/>" & now.ToString("O")) ' Output : 2013-08-14T17:12:30.1324811+05:30
Response.Write("<BR/>" & now.ToString("s")) ' Output : 2013-08-14T17:12:30
Response.Write("<BR/>" & now.ToString("t")) ' Output : 5:12 PM
Response.Write("<BR/>" & now.ToString("T")) ' Output : 5:12:30 PM
Response.Write("<BR/>" & now.ToString("u")) ' Output : 2013-08-14 17:12:30Z
Response.Write("<BR/>" & now.ToString("U")) ' Output : Wednesday, August 14, 2013 11:42:30 AM
Response.Write("<BR/>" & now.ToString("y")) ' Output : August, 2013
Response.Write("<BR/>" & now.ToString("Y")) ' Output : August, 2013
Response.Write("<BR/>" & "------------------------")
Response.Write("<BR/>" & now.ToLongDateString()) ' Output : Wednesday, August 14, 2013
Response.Write("<BR/>" & now.ToLongTimeString()) ' Output : 5:12:30 PM
Response.Write("<BR/>" & now.ToShortDateString()) ' Output : 14-Aug-13
Response.Write("<BR/>" & now.ToShortTimeString()) ' Output : 5:12 PM
Response.Write("<BR/>" & now.ToString()) ' Output : 14-Aug-13 5:12:30 PM
End Sub
Reference site: http://www.webcodeexpert.com/2013/08/date-and-time-formats-in-aspnet-using.html#.Uk6o99KBnCY
How to get IP address in Sql server.
SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') [Machine Name]
,SERVERPROPERTY('InstanceName') AS [Instance Name]
,LOCAL_NET_ADDRESS AS [IP Address Of SQL Server]
,CLIENT_NET_ADDRESS AS [IP Address Of Client]
FROM SYS.DM_EXEC_CONNECTIONS
WHERE SESSION_ID = @@SPID
Friday, 21 June 2013
Programatically create buttons in code behind
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultipleDynamicButtons.aspx.cs" Inherits="WebUI.Forums.MultipleDynamicButtons" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:PlaceHolder runat="server" ID="place" /><br /> <asp:Literal runat="server" ID="lit" /> </div> </form> </body> </html>
.CS Page
using System;
using System.Web.UI.WebControls;
namespace WebUI.Forums
{
public partial class MultipleDynamicButtons : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
Button btn = new Button();
btn.ID = "Button" + i.ToString();
btn.Text = "Test button" + i.ToString();
btn.Click += new EventHandler(btn_Click);
place.Controls.Add(btn);
}
}
void btn_Click(object sender, EventArgs e)
{
lit.Text = string.Format("Button {0} was pressed.", ((Button)sender).ID);
}
}
}
Subscribe to:
Posts (Atom)
