<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>AngularJS Tutorial</title> <script src="//mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script> <script type="text/javascript"> function load() { var doc = new jsPDF(); doc.setFontSize(12); doc.text(35, 25, "Welcome to JsPDF"); doc.autoPrint(); var string = doc.output('datauristring'); var iframe = "<iframe width='100%' height='100%' src='" + string + "'></iframe>" var x = window.open(); x.document.open(); x.document.write(iframe); x.document.close(); }; </script> </head> <body > <input onclick="load()" type="button" value="click" /> </body> </html>
Showing posts with label Code Helper. Show all posts
Showing posts with label Code Helper. Show all posts
Monday, June 29, 2015
jsPdf Print without browser history
Sunday, June 21, 2015
Angular Js $index, $odd and $even with ng-if directive
<!DOCTYPE html> <html> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng-repeat="x in names"> <td ng-if="$odd" style="background-color:#a1a1a1; color:#ffffff"> {{$index + 1 }} </td> <td ng-if="$even"> {{ $index + 1 }} </td> <td ng-if="$odd" style="background-color:#a1a1a1; color:#ffffff"> {{ x.Name }} </td> <td ng-if="$even"> {{ x.Name }} </td> <td ng-if="$odd" style="background-color:#a1a1a1; color:#ffffff"> {{ x.Country }} </td> <td ng-if="$even"> {{ x.Country }} </td> </tr> </table> </div> <script> angular.module('myApp', []) .factory('customersService', function ($http, $q) { var deferred = $q.defer(); return { getPerson: function () { return $http.get("/api/Home/getperson") .then(function (response) { // promise is fulfilled deferred.resolve(response); return deferred.promise; }, function (response) { deferred.reject(response); return deferred.promise; }) ; } } }) .controller("customersCtrl", function ($scope, $q, customersService) { customersService.getPerson().then( function (result) { $scope.names = result.data; }, function (error) { // handle errors here alert('error'); } ); }); </script> </body> </html>
Tuesday, June 16, 2015
Angular Js Factory and $q
<!DOCTYPE html> <html> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="customersCtrl"> <ul> <li ng-repeat="x in names"> {{ x.Name + ', ' + x.Country }} </li> </ul> </div> <script> angular.module('myApp', []) .factory('customersService', function ($http, $q) { var deferred = $q.defer(); return { getPerson: function () { return $http.get("/api/Home/getperson") .then(function (response) { // promise is fulfilled deferred.resolve(response); return deferred.promise; }, function (response) { deferred.reject(response); return deferred.promise; }) ; } } }) .controller("customersCtrl", function ($scope, $q, customersService) { customersService.getPerson().then( function (result) { $scope.names = result.data; }, function (error) { // handle errors here alert('error'); } ); }); </script> </body> </html>
Friday, June 12, 2015
Retrieve Data in Angular Js from Web Api as HttpResponseMessage
<!DOCTYPE html> <html> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="customersCtrl"> <ul> <li ng-repeat="x in names"> {{ x.Name + ', ' + x.Country }} </li> </ul> </div> <script> var app = angular.module('myApp', []); app.controller('customersCtrl', function ($scope, $http) { $http.get("/api/Home/getperson").success(function (data) { alert(JSON.stringify(data)); $scope.names = data; }); }); </script> </body> </html> public class records { public string Name { get; set; } public string City { get; set; } public string Country { get; set; } } public class HomeController : ApiController { public HttpResponseMessage getperson() { var data = new List(); records item1 = new records(); item1.Name = "Name1"; item1.City = "City1"; item1.Country = "Country1"; data.Add(item1); records item2 = new records(); item2.Name = "Name2"; item2.City = "City2"; item2.Country = "Country2"; data.Add(item2); records item3 = new records(); item3.Name = "Name3"; item3.City = "City3"; item3.Country = "Country3"; data.Add(item3); return Request.CreateResponse(HttpStatusCode.OK, data); } }
Thursday, June 11, 2015
Angular Js Upper Case And Lower Case
<!DOCTYPE html> <html> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="personCtrl"> <p>The name is {{ firstName | uppercase }}</p> <p>The name is {{ lastName | lowercase }}</p> </div> <script type="text/javascript"> angular.module('myApp', []).controller('personCtrl', function ($scope) { $scope.firstName = "jobin"; $scope.lastName = "jonny"; }); </script> </body> </html>
Monday, April 6, 2015
File Download using Java Script
<script> function saveTextAsFile() { var textToWrite = document.getElementById("inputTextToSave").value; var textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' }); var fileNameToSaveAs = "myNewFile.txt"; var downloadLink = document.createElement("a"); downloadLink.download = fileNameToSaveAs; downloadLink.innerHTML = "My Hidden Link"; window.URL = window.URL || window.webkitURL; downloadLink.href = window.URL.createObjectURL(textFileAsBlob); downloadLink.onclick = destroyClickedElement; downloadLink.style.display = "none"; document.body.appendChild(downloadLink); downloadLink.click(); } function destroyClickedElement(event) { document.body.removeChild(event.target); } </script> </head> <body> <textarea id="inputTextToSave" style="width:512px;height:256px"></textarea> <button onclick="saveTextAsFile()">Save Text to File</button> </body>
Saturday, March 28, 2015
Encryption and Decryption in javascript and c#
javascript <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js "></script> <script type="text/javascript"> function SubmitsEncry() { debugger; var txtUserName = "Please enter UserName"; var key = CryptoJS.enc.Utf8.parse('8080808080808080'); var iv = CryptoJS.enc.Utf8.parse('8080808080808080'); var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(txtUserName), key, { keySize: 128 / 8, iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); var decrypted = CryptoJS.AES.decrypt(encrypted, key, { keySize: 128 / 8, iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); alert(decrypted.toString(CryptoJS.enc.Utf8)); } SubmitsEncry(); </script> c# public ActionResult Index() { string s = "The brown fox jumped over the green frog"; //string k = "urieurut"; var encry = EncryptStringAES(s); var sss = DecryptStringAES(encry); return View(); } public static string DecryptStringAES(string cipherText) { var keybytes = Encoding.UTF8.GetBytes("8080808080808080"); var iv = Encoding.UTF8.GetBytes("8080808080808080"); var encrypted = Convert.FromBase64String(cipherText); var decriptedFromJavascript = DecryptStringFromBytes(encrypted, keybytes, iv); return string.Format(decriptedFromJavascript); } private static string DecryptStringFromBytes(byte[] cipherText, byte[] key, byte[] iv) { // Check arguments. if (cipherText == null || cipherText.Length <= 0) { throw new ArgumentNullException("cipherText"); } if (key == null || key.Length <= 0) { throw new ArgumentNullException("key"); } if (iv == null || iv.Length <= 0) { throw new ArgumentNullException("key"); } // Declare the string used to hold // the decrypted text. string plaintext = null; // Create an RijndaelManaged object // with the specified key and IV. using (var rijAlg = new RijndaelManaged()) { //Settings rijAlg.Mode = CipherMode.CBC; rijAlg.Padding = PaddingMode.PKCS7; rijAlg.FeedbackSize = 128; rijAlg.Key = key; rijAlg.IV = iv; // Create a decrytor to perform the stream transform. var decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV); try { // Create the streams used for decryption. using (var msDecrypt = new MemoryStream(cipherText)) { using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (var srDecrypt = new StreamReader(csDecrypt)) { // Read the decrypted bytes from the decrypting stream // and place them in a string. plaintext = srDecrypt.ReadToEnd(); } } } } catch { plaintext = "keyError"; } } return plaintext; } public static string EncryptStringAES(string plainText) { var keybytes = Encoding.UTF8.GetBytes("8080808080808080"); var iv = Encoding.UTF8.GetBytes("8080808080808080"); var encryoFromJavascript = EncryptStringToBytes(plainText, keybytes, iv); return Convert.ToBase64String(encryoFromJavascript); } private static byte[] EncryptStringToBytes(string plainText, byte[] key, byte[] iv) { // Check arguments. if (plainText == null || plainText.Length <= 0) { throw new ArgumentNullException("plainText"); } if (key == null || key.Length <= 0) { throw new ArgumentNullException("key"); } if (iv == null || iv.Length <= 0) { throw new ArgumentNullException("key"); } byte[] encrypted; // Create a RijndaelManaged object // with the specified key and IV. using (var rijAlg = new RijndaelManaged()) { rijAlg.Mode = CipherMode.CBC; rijAlg.Padding = PaddingMode.PKCS7; rijAlg.FeedbackSize = 128; rijAlg.Key = key; rijAlg.IV = iv; // Create a decrytor to perform the stream transform. var encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV); // Create the streams used for encryption. using (var msEncrypt = new MemoryStream()) { using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { using (var swEncrypt = new StreamWriter(csEncrypt)) { //Write all data to the stream. swEncrypt.Write(plainText); } encrypted = msEncrypt.ToArray(); } } } // Return the encrypted bytes from the memory stream. return encrypted; }
Monday, January 5, 2015
Tree View Structure From DataBase
[HttpGet] public ListgetValue(int id) { var dataList = nodeList().Where(x => x.parentID == 0).ToList(); List nList = new List (); foreach (var item in dataList) { node i = new node(); i.name = item.name; FillChild(i, item.ID); nList.Add(i); } return nList; } public static List nodeList() { var nodeList = new List (); var node1 = new nodeDB(); node1.ID = 1; node1.name = "node1"; node1.parentID = 0; nodeList.Add(node1); var node2 = new nodeDB(); node2.ID = 2; node2.name = "node2"; node2.parentID = 1; nodeList.Add(node2); var node3 = new nodeDB(); node3.ID = 3; node3.name = "node3"; node3.parentID = 2; nodeList.Add(node3); var node4 = new nodeDB(); node4.ID = 4; node4.name = "node4"; node4.parentID = 0; nodeList.Add(node4); var node5 = new nodeDB(); node5.ID = 5; node5.name = "node5"; node5.parentID = 4; nodeList.Add(node5); return nodeList; } public int FillChild(node parent, int ID) { var data = nodeList().Where(x => x.parentID == ID).ToList(); if (data.Count > 0) { foreach (var item in data) { node child = new node(); child.name = item.name; int tempID = item.ID; parent.nodes.Add(child); FillChild(child, tempID); } return 0; } else { return 0; } }
Saturday, January 3, 2015
AngularJs Bootstrap TreeView
<!DOCTYPE html> <html ng-app="plunker"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js"></script> <script src="http://ci.angularjs.org/job/angularui-bootstrap/ws/dist/ui-bootstrap-tpls-0.1.1-SNAPSHOT.js"></script> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" /> @*<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">*@ <script src="~/Script/app/Home/DialogDeomoCtrl.js"></script> <link href="~/CSS/stytree.css" rel="stylesheet" /> </head> <body> <div ng-controller="DialogDemoCtrl" > <div class="span5 article-tree"> <div ng-style="{'overflow': 'auto'}" > <script type="text/ng-template" id="tree_item_renderer" > <span ng-click="nodeClicked(data)" > <i class="{{ switcher( isLeaf(data), '', 'icon-minus-sign' )}}"></i> {{showNode(data)}} </span> <a href="">{{data.name + ' Edit'}}</a> <ul class="some" ng-show="data.show"> <li ng-repeat="data in data.nodes" class="parent_li" ng-include="'tree_item_renderer'" tree-node></li> </ul> </script> <div class="tree well"> <ul> <li ng-repeat="data in displayTree" ng-include="'tree_item_renderer'" data-ng-click="loadconfig()"></li> </ul> </div> </div> </div> </div> </body> </html> angular.module('plunker', ['ui.bootstrap', 'ngResource']); function DialogDemoCtrl($scope, $dialog, $resource) { //$scope.isExecuted = false; //buildEmptyTree(); $scope.title = "visible"; $scope.count = 0; $scope.loadconfig = function () { if ($scope.count == 0) { treeConfig(); $scope.count = 1; } console.log('load: ' + new Date().getMilliseconds()); } read('getvalue', { id: 123 }); $scope.selectedNode = ""; $scope.showNode = function (data) { //console.log(data); return data.name; }; $scope.isClient = function (selectedNode) { if (selectedNode == undefined) { return false; } if (selectedNode.device_name != undefined) { return true; } return false; }; function read(action, params) { console.log('read: ' + new Date().getMilliseconds()); var resource = $resource('api/Home/' + action, params, { action: { method: 'GET', isArray: true } }); resource.action(params).$promise.then(function (d) { $scope.displayTree = d; }); }; } function treeConfig() { var title = $('.tree li:has(ul)').find('.parent_li').find(' > span').attr('title'); if (title == undefined) { // alert(title + " out"); $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch'); } $('.tree li.parent_li > span').on('click', function (e) { var children = $(this).parent('li.parent_li').find(' > ul > li'); if (children.is(":visible")) { var title = $(this).attr('title'); // alert(title + " visible"); if (title == "Collapse this branch") { children.hide('fast'); $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign'); } } else if (children.is(":hidden")) { var title = $(this).attr('title'); // alert(title + " hidden"); if (title == "Expand this branch") { children.show('fast'); $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign'); } } e.stopPropagation(); }); } .tree { min-height:20px; padding:19px; margin-bottom:20px; background-color:#fbfbfb; border:1px solid #999; -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px; -webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05); -moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05); box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05) } .tree li { list-style-type:none; margin:0; padding:10px 5px 0 5px; position:relative } .tree li::before, .tree li::after { content:''; left:-20px; position:absolute; right:auto } .tree li::before { border-left:1px solid #999; bottom:50px; height:100%; top:0; width:1px } .tree li::after { border-top:1px solid #999; height:20px; top:25px; width:25px } .tree li span { -moz-border-radius:5px; -webkit-border-radius:5px; border:1px solid #999; border-radius:5px; display:inline-block; padding:3px 8px; text-decoration:none } .tree li.parent_li>span { cursor:pointer } .tree>ul>li::before, .tree>ul>li::after { border:0 } .tree li:last-child::before { height:30px } .tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span { background:#eee; border:1px solid #94a0b4; color:#000 }
Tuesday, October 21, 2014
URL Rewrite
void Application_BeginRequest(object sender, EventArgs e) { string URL_Path = Request.Path.ToLower(); if (URL_Path.StartsWith("/news/")) { URL_Path = URL_Path.Trim('/'); string NewsID = URL_Path.Substring(URL_Path.IndexOf("/")); HttpContext MyContext = HttpContext.Current; MyContext.RewritePath("/default.aspx?News=" + NewsID); } }
Thursday, October 17, 2013
Update Pannel
<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label2" runat="server" ForeColor="red" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label1" runat="server" /><br /> <asp:Button ID="Button1" runat="server" Text="Update Both Panels" OnClick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="Update This Panel" OnClick="Button2_Click" /> </ContentTemplate> </asp:UpdatePanel>
Tuesday, October 15, 2013
sql reader
public DataTable ExecuteRreader(string sp_name, Dictionary<string, object> parameters) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { SqlCommand sqlCommand = new SqlCommand(sp_name, sqlConnection); sqlCommand.CommandType = CommandType.StoredProcedure; if (parameters != null) { foreach (KeyValuePair<string, object> parameter in parameters) sqlCommand.Parameters.AddWithValue(parameter.Key, parameter.Value); } DataTable dataTable = new DataTable(); sqlConnection.Open(); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) { dataTable.Load(sqlDataReader); } return dataTable; } }
Sunday, October 13, 2013
autocomplete WebMothod with select event
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"> </script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"> </script> <link type="text/css" rel="Stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <script type="text/javascript"> $(document).ready(function() { $("#nameText").autocomplete({ source: function (request, response) { $.ajax({ url: "Default4.aspx/getdatas", data: "{strterm: '" + request.term + "'}", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { response($.map(data.d, function (item) { return { label: item.label , value: item.record, id: item.type, first: item.key, last: item.key } })) }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); }, select: function (event, ui) { $("#TextBox1").val(ui.item.id); }, minLength: 1 }).data("ui-autocomplete")._renderItem = function (ul, item) { return $("<li></li>") .data("item.autocomplete", item) .append("<a>" + item.label + item.value + item.id + item.first + "</a>") .appendTo(ul); }; }); </script>
autocomplete jquery with select event
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"> </script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"> </script> <link type="text/css" rel="Stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <script type="text/javascript"> $(function () { var availableItems = [{ value: "recent", label: "Recent", classN: "heading" }, { value: "all", label: "All", classN: "all" }, { value: "lorem", label: "Lorem", classN: "lorem" }, ]; $(".post-to").autocomplete({ source: availableItems, minLength: 0, focus: function (event, ui) { $('.post-to').val(ui.item.label); alert(ui.item.label); return false; }, select: function (event, ui) { alert(ui.item.label); return false; } }).on("focus", function () { $(this).autocomplete("search", ''); }).data("ui-autocomplete")._renderItem = function (ul, item) { return $("<li></li>") .data("item.autocomplete", item) //instead of <span> use <a> .append("<a class='" + item.classN + "'></a><a>" + item.label + "</a>") .appendTo(ul); }; }); </script>
Wednesday, September 4, 2013
Crystal Report bind from source code
<div> <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" Height="1039px" Width="901px" /> </div> using System.Data.SqlClient; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.ReportSource; using CrystalDecisions.Shared; private ReportDocument rpt; protected void Page_Load(object sender, EventArgs e) { ConfigureCrystalReports(); string connection = @"DATA SOURCE=JOSE-PC\SQLEXPRESS;DATABASE=MedicalDB;Integrated Security=True;"; using (SqlConnection sqlConnection = new SqlConnection(connection)) { string query = "SELECT * FROM [MedicalDB].[dbo].[CrystalReport]"; SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); sqlDataAdapter.SelectCommand = sqlCommand; DataSet ds = new DataSet(); sqlDataAdapter.Fill(ds); // ds.Tables[0].Rows[0]["Photo"] = (byte[])System.IO.File.ReadAllBytes(Server.MapPath("Penguins.jpg")); rpt.SetDataSource( ds.Tables[0]); CrystalReportViewer1.ReportSource = rpt; CrystalReportViewer1.RefreshReport(); } } private void ConfigureCrystalReports() { rpt = new ReportDocument(); string reportPath = Server.MapPath("CrystalReport.rpt"); rpt.Load(reportPath); ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.DatabaseName = "MedicalDB"; connectionInfo.IntegratedSecurity = true; //connectionInfo.UserID = ""; //connectionInfo.Password = "user123"; SetDBLogonForReport(connectionInfo, rpt); } private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument) { Tables tables = reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) { TableLogOnInfo tableLogonInfo = table.LogOnInfo; tableLogonInfo.ConnectionInfo = connectionInfo; table.ApplyLogOnInfo(tableLogonInfo); } } byte[] imgdata = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath(path)); create dataset and add fields to CrystalReport.rpt
Sunday, August 11, 2013
Bind DropDownList in Edit Footer And Empty templates
if (e.Row.RowType == DataControlRowType.DataRow && gridCategory.EditIndex ==e.Row.RowIndex) { string MenuName = ((HiddenField)e.Row.FindControl("hiddenMenuName")).Value; DropDownList ddlMenu = (DropDownList)e.Row.FindControl("ddlMenu"); bindddMenu(ddlMenu, MenuName); } else if (e.Row.RowType == DataControlRowType.Footer) { DropDownList ddlMenu = (DropDownList)e.Row.FindControl("ddlMenu"); bindddMenu(ddlMenu, ""); } else if (e.Row.RowType == DataControlRowType.EmptyDataRow) { DropDownList ddlMenu = (DropDownList)e.Row.Controls[0].Controls[0].FindControl("ddlMenu"); bindddMenu(ddlMenu, ""); } OR protected void gridCategory_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.EmptyDataRow) { DropDownList ddlMenu = (DropDownList)e.Row.FindControl("ddlMenu"); bindddMenu(ddlMenu, ""); } }
Thursday, August 8, 2013
CSS For Grid
<style type="text/css"> .grid { border:1px solid #111111; margin: 5px 0 10px 0; width:95%; font-size:1.2em; } .grid a:link { color:#114477; } .grid tr th { background-color:#336699; color:#FFFFFF; height:25px; font-weight:bold; } .grid tr, .grid th, .grid td { padding:5px; } .grid tr { background-color:#FFFFFF; color:#222222; } .grid tr.alt { background-color:#EDEDED; color:#222222; } .grid .pgr td { background-color:#bdbdbd; font-weight: bold; color:#555555; padding:1px; } .grid .pgr td a { padding:1px; } .grid .pgr td span { padding:1px; } </style>
Sunday, July 28, 2013
Forms Authentication
void Application_AuthenticateRequest(object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated) { if (HttpContext.Current.User.Identity is FormsIdentity) { FormsIdentity formsIdentity = (FormsIdentity)HttpContext.Current.User.Identity; string[] userRoles = formsIdentity.Ticket.UserData.Split(','); HttpContext.Current.User = new GenericPrincipal(formsIdentity, userRoles); } } } } protected void Login_Click(object sender, EventArgs e) { FormsAuthenticationTicket formsAuthenticationTicket = new FormsAuthenticationTicket(1, "abcd", DateTime.Now, DateTime.Now.AddMinutes(30), false, "Admin"); string encryptedFAT = FormsAuthentication.Encrypt(formsAuthenticationTicket); HttpCookie httpcookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedFAT); HttpContext.Current.Response.Cookies.Add(httpcookie); string returnURL = Request.QueryString["returnURL"]; if (returnURL == null) { Response.Redirect(returnURL); } else Response.Redirect("Default.aspx"); } <authentication mode="Forms"> <forms defaultUrl="Default.aspx" loginUrl="Login.aspx"> </forms> </authentication> <authorization> <allow roles="Admin"/> <deny users="*"/> </authorization>
Thursday, June 20, 2013
Jquery Image Gallery
<script type="text/javascript" src="script/jquery.1.9.min.js"></script> <script type="text/javascript"> var imageList; var start = 0; var autoImagesLoadID; $(document).ready(function () { $.ajax({ type: "POST", url: "Default.aspx/galleryPhotos", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { imageList = data.d; loadImages(imageList); autoImagesLoad(imageList); } }); function autoImagesLoad(imgList) { autoImagesLoadID = setInterval(function () { if (start + 1 > imgList.length) { start = 0; } else { start = start + 1; } $("#content > div.box > div.image > img").attr("src", "upload/" + imgList[start].photoPath); if (start % 5 == 0) { var $divthumbs = $("#content > div.box > div.thumbs").empty().append(""); for (var i = start; i < start + 5; i++) { if (imgList[i] && imgList[i].photoPath.length > 1) { var $div = $("<div/>").attr("class", "thumb").attr("title", imgList[i].rowID); var $divT = $("<div/>").attr("class", "imgthumb"); var $a = $("<a/>").attr("href", "javascript:;"); var $img = $("<img/>").attr("src", "upload/" + imgList[i].photoPath).appendTo($a); $divT.append($a).appendTo($div); $divthumbs.append($div); } } } $("#content > div.box > div.thumbs > div.thumb").css("background-color", ""); $("#content > div.box > div.thumbs > div.thumb[title~=" + (start + 1) + "]").css("background-color", "Blue"); }, 3000); } function loadImages(imgList) { $("#content > div.box > div.image > img").attr("src", "upload/" + imgList[start].photoPath); var $divthumbsTemp = $("<div/>"); for (var i = start; i < start + 5; i++) { if (imgList[i] && imgList[i].photoPath.length > 1) { var $div = $("<div/>").attr("class", "thumb").attr("title", imgList[i].rowID); if (i == 0) { $div.css("background-color", "Blue"); } var $divT = $("<div/>").attr("class", "imgthumb"); var $a = $("<a/>").attr("href", "javascript:;"); var $img = $("<img/>").attr("src", "upload/" + imgList[i].photoPath).appendTo($a); $divT.append($a).appendTo($div); $divthumbsTemp.append($div); } } $("#content > div.box > div.thumbs").empty().html($divthumbsTemp.html()); } $("#content > div.box > div.arrowleft").click(function () { if (start - 5 < 0) start = 0; else start = start - 5; $("#content > div.box > div.thumbs").animate({ "margin-right": "85%", height: "73px", width: "1px" }, "slow", function () { loadImages(imageList); }); $("#content > div.box > div.thumbs").animate({ "margin-right": "0%", height: "73px", width: "545px" }, "slow"); }); $("#content > div.box > div.arrowright").click(function () { if (start + 5 < imageList.length) start = start + 5; $("#content > div.box > div.thumbs").animate({ "margin-left": "85%", height: "73px", width: "1px" }, "slow", function () { loadImages(imageList); }); $("#content > div.box > div.thumbs").animate({ "margin-left": "0%", height: "73px", width: "545px" }, "slow"); }); $("#content > div.box > div.thumbs").on("mouseenter", "div.thumb", function () { start = ($(this).attr("title")) - 1; $("#content > div.box > div.image > img").attr("src", "upload/" + imageList[start].photoPath); $("#content > div.box > div.thumbs > div.thumb").css("background-color", ""); }); $("#content > div.box").mouseover(function () { clearInterval(autoImagesLoadID); }); $("#content > div.box").mouseout(function () { autoImagesLoad(imageList); }); }); </script> <!--begin pbox--> <div class="box"> <h3>Image Description</h3> <!-- begin post --> <div class="image"> <img src="" height="400px" width="640px" alt="" /></div> <!-- end post --> <div class="arrowleft"><a href="javascript:void(0)"><img src="images/left.png" alt="" /></a></div> <div class="thumbs"> </div> <div class="arrowright"><a href="javascript:void(0)"><img src="images/right.png" alt="" /></a></div> <div class="break"></div> </div> <!--end p bbox-->
Saturday, February 9, 2013
Create User In MVC Membership
if (ModelState.IsValid) { MembershipCreateStatus membershipCreateStatus; Membership.CreateUser(userRegistration.userName, userRegistration.password, userRegistration.emailID, userRegistration.securityQuestion, userRegistration.securityAnswer, true, out membershipCreateStatus); if (membershipCreateStatus == MembershipCreateStatus.Success) { Roles.AddUserToRole(userRegistration.userName, "UserRole"); return RedirectToAction("Index", "Account"); } else { ModelState.AddModelError("", "Registration Unsuccessful, Please Try again"); return View(userRegistration); } } else { return View(userRegistration); }
Subscribe to:
Posts (Atom)