JQuery calendar to display event data from Database

Hello,

Try this example to use JQuery calendar to display event data from Database


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

<!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>
	<link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
 <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<style>
* {
margin: 0 auto;
padding: 0;
}

body {
background-color: #F2F2F2;
}

.container {
margin: 0 auto;
width: 920px;
padding: 50px 20px;
background-color: #fff;
}

h3 {
text-align: center;
}

#calendar {
margin-top: 40px;
}

.event a {
background-color: #42B373 !important;
background-image: none !important;
color: #ffffff !important;
}
</style>

<script type="text/javascript">
 var eventDates = {};
 $(function () {
 $.ajax({
 type: "POST",
 url: "Default2.aspx/GetEvents",
 data: '{}',
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: OnSuccess,
 failure: function (response) {
 alert(response.d);
 },
 error: function (response) {
 alert(response.d);
 }
 });
 });

function OnSuccess(response) {
 $(response.d).each(function (i, e) {
 eventDates[convertDate(e.EventDate)] = convertDate(e.EventDate);
 });

$('#calendar').datepicker({
 beforeShowDay: function (date) {
 var highlight = eventDates[convertDate(date)];
 // alert(highlight);
 if (highlight) {
 return [true, "event", highlight];
 } else {
 return [true, '', ''];
 }
 }
 });
 }

function convertDate(inputFormat) {
 function pad(s) { return (s < 10) ? '0' + s : s; }
 var d = new Date(inputFormat);
 return [pad(d.getDate()), pad(d.getMonth() + 1), d.getFullYear()].join('/');
 }

</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h3>Highlight Particular Dates in JQuery UI Datepicker</h3>
<div id="calendar"></div>
</div>
</form>
</body>
</html>

In Code behind :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

public partial class Default2 : System.Web.UI.Page
{
[WebMethod]
public static List<Event> GetEvents()
{
List<Event> events = new List<Event>();
events.Add(new Event()
{
EventID = 1,
EventName = "EventName 1",
EventDate = DateTime.Now.ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
events.Add(new Event()
{
EventID = 2,
EventName = "EventName 2",
EventDate = DateTime.Now.AddDays(4).ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
events.Add(new Event()
{
EventID = 3,
EventName = "EventName 3",
EventDate = DateTime.Now.AddDays(10).ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
events.Add(new Event()
{
EventID = 4,
EventName = "EventName 4",
EventDate = DateTime.Now.AddDays(22).ToString("MM-dd-yyyy"),
EventDetail = string.Empty
});
return events;
}

protected void Page_Load(object sender, EventArgs e)
{

}
}

Hope this helps

Good Luck.

Categories: ASP.Net, Jquery

Programmatically Creating Site Backup in SharePoint

April 29, 2017 Leave a comment

Hello all,

try this example to Create Site Backup in SharePoint from Code


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SiteBackUp
{
public class SiteBackup
{
static void Main(string[] args)
{
siteBackup("http://servername:portnumber","SharePointSiteBackup");
}
public static void siteBackup(string siteURL,string fileName)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using(SPSite objSite=new SPSite(siteURL))
{
using(SPWeb objWeb=objSite.OpenWeb())
{
bool currentSiteStatus=objSite.AllowUnsafeUpdates;
objSite.AllowUnsafeUpdates=true;
bool currentWebStatus=objWeb.AllowUnsafeUpdates;
objWeb.AllowUnsafeUpdates=true;
string comment = objWeb.Title+"- Creating Backup is completed";
SPSiteCollection siteCollection=objSite.WebApplication.Sites;
objSite.ReadOnly=true;
string time=DateTime.Now.ToString("dd-MM-yyyy");
string backupName= "D:\\SiteBackup\\Backup" + fileName+"_"+time+".bak";
siteCollection.Backup(siteURL,backupName,false);
objSite.AllowUnsafeUpdates=currentSiteStatus;
objWeb.AllowUnsafeUpdates=currentWebStatus;
if(objSite.ReadOnly==true)
{
objSite.ReadOnly=false;
siteBackupLog(comment);
}
}
}
});
}
catch (Exception ex)
{
SPSite site = new SPSite(siteURL);
if (site.ReadOnly == true)
site.ReadOnly = false;
siteBackupLog(ex.Message);
}
}

public static void siteBackupLog(string message)
{
string PathName = "C:\\SiteBackup logs\\";
PathName = PathName + "Backuplog-" + DateTime.Now.ToString("dd-MM-yyyy") + ".log";
StreamWriter sw = new StreamWriter(PathName, true);
sw.WriteLine(message + " - " + DateTime.Now);
sw.Flush();
sw.Close();
}
}
}

Good Luck

Categories: SharePoint 2010

Display Sum (Total) of Checked GridView Rows on CheckBox check using jQuery in ASP.Net

March 27, 2017 Leave a comment

Dears,

Try this example to Display Sum (Total) of Checked GridView Rows on CheckBox check using jQuery in ASP.Net

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
 <script type="text/javascript">
 $(function () {
 $('[id*=chk]').on('change', function () {
 var value = 0;
 $('[id*=chk]:checked').each(function () {
 var row = $(this).closest('tr');
 value = value + parseInt(row.find('[id*=lblValue]').html());
 });
 $('[id*=lblTotal]').html(value);
 });
 });
 </script>
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Values">
<ItemTemplate>
<asp:Label ID="lblValue" runat="server" Text='<%# Eval("Value") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblTotal" runat="server" />

In Code behind :

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Value", typeof(int)) });
dt.Rows.Add(10);
dt.Rows.Add(20);
dt.Rows.Add(30);
dt.Rows.Add(40);
gvData.DataSource = dt;
gvData.DataBind();
}
}

Hope this helps

Good Luck.

Categories: ASP.Net, Jquery

Convert Text in TextBox to Upper Using JavaScript

February 20, 2017 Leave a comment

Hi all,

Try this example to Convert Text in TextBox to Upper using Javascript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
 function Capital(txt) {
 txt.value = txt.value.replace(/^\s+/, '').toUpperCase();
 }
 </script>
</head>
<body>
Enter Name:
<input type="text" value=" " onkeyup="Capital(this)" />
</body>
</html>

Hope this helps

Good Luck.

Categories: ASP.Net

Validate IBAN Using C#

January 5, 2017 Leave a comment

Hi all,

Try this example to Validate IBAN Using C#

public static bool ValidateBankAccount(string bankAccount)
{
bankAccount = bankAccount.ToUpper(); //IN ORDER TO COPE WITH THE REGEX BELOW
if (String.IsNullOrEmpty(bankAccount))
return false;
else if (System.Text.RegularExpressions.Regex.IsMatch(bankAccount, "^[A-Z0-9]"))
{
bankAccount = bankAccount.Replace(" ", String.Empty);
string bank =
bankAccount.Substring(4, bankAccount.Length - 4) + bankAccount.Substring(0, 4);
int asciiShift = 55;
StringBuilder sb = new StringBuilder();
foreach (char c in bank)
{
int v;
if (Char.IsLetter(c)) v = c - asciiShift;
else v = int.Parse(c.ToString());
sb.Append(v);
}
string checkSumString = sb.ToString();
int checksum = int.Parse(checkSumString.Substring(0, 1));
for (int i = 1; i < checkSumString.Length; i++)
{
int v = int.Parse(checkSumString.Substring(i, 1));
checksum *= 10;
checksum += v;
checksum %= 97;
}
return checksum == 1;
}
else
return false;
} 

Hope this helps

Good Luck

Categories: ASP.Net

Get Current Page Name

December 6, 2016 Leave a comment

Hi all,

Try this example to Get Current Page Name

public static string GetCurrentPageName()
{
string sPath = HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}

Hope this helps

Good Luck.

Categories: ASP.Net

Validate Rad ComboBox

November 6, 2016 Leave a comment

Hi all,

Try this example to Validate Rad ComboBox Using ASP.Net Validation Controls


<script type="text/javascript">
 function validateddlType(source, args) {
 args.IsValid = false;
 var combo = $find("<%= ddlType.ClientID %>");
 var text = combo.get_text();
 if (text.length < 1) {
 args.IsValid = false;
 }
 else {
 var node = combo.findItemByText(text);
 if (node) {
 args.IsValid = true;
 }
 else {
 args.IsValid = false;
 }
 }
 }

</script>

<telerik:radcombobox id="ddlType" allowcustomtext="True" runat="server" emptymessage="--- Please Select ---" filter="Contains" skin="Telerik"></telerik:radcombobox>
<asp:RequiredFieldValidator ID="rfvType" ControlToValidate="ddlType" ForeColor="Red" runat="server" Display="Dynamic" ErrorMessage="Value is required" ValidationGroup="A"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="cvType" ClientValidationFunction="validateddlType" ForeColor="Red" ControlToValidate="ddlType" ValidationGroup="A" runat="server" ErrorMessage="Please select a vaild Value"></asp:CustomValidator>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript