A person on the forums was struggling with jQuery tools tabs index issue on postback. On clicking the tabs and doing some postback the selected tab index was getting lost. Below is the solution on how to retaing the previous selected index which was there before postback. Complete Source: <%@ Page Language="C#" %> <script type="text/javascript"> </script> <%@ Import ...
I was working with jQuery tools tabs today and I had to set the initial index of tab selected by default. The solution is to set initialindex property in the options. Source: $("ul.tabs").tabs("div.panes > div", { initialIndex: 1 }) ; Complete code to test above: <html> <head> <title>jQuery Tools standalone demo</title> <script src="http://cdn.jquerytools.or...
A person asked me today how to get form authentication cookie and get the data present in it. I decided to write a short blog on it. Formauthentication cookie is saved with the name which we can get via FormsAuthentication.FormsCookieName property. The key here is to get the cookie via this name and Decrypt the data present in the cookie to get the data. Below is the code: HttpCookie aut...
While working with one of the sample application I noticed that form authentication timeout in web.config was overriding the manual ticket's (which we created via code) timeout. Below is the code which was written in the application: var ticket = new FormsAuthenticationTicket(1, "UserName", DateTime.Now, DateTime.Now.AddMinutes(1), true, "Password"); string ticketValue = FormsAuthenticat...
In this blog I will show how to select a range of characters in textbox with jquery. In my demo I have used one textbox and one button. On click of button arange of characters in textbox will be selected. Below is the sample code: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="http://ajax.go...
Recently we moved from Newtonsoft.Json 3.5 to 4.0 version. We noticed that we were getting Could not load file or assembly 'Newtonsoft.Json, Version=3.5.0.0.. while working with Twitter authentication which we were using in our application. The third party dll which we were using for Twitter authentication was demanding Newstonsoft.Json 3.5 internally. So we had two ways to solve this ei...
In this blog I will show how to remove a css class from an asp.net control from codebehind. It can be done just by replacing the particular class in CSSClass property value of that control with empty string. Below is the complete code: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .bold { font-weigh...
Following is the JavaScript code to check whether a key is present in querystring or not: <script type="text/javascript"> var queryKeyPresent = function(key) { var url = window.location.href; if (url.indexOf('?' + key + '=') != -1) { return true; } else if (url.indexOf('&' + key + '=') != -1) { return true; } return false; }; </script> Usage: var check = queryKeyPresent('...
Below is the script to get list of stored procedures in last n days. SELECT [name] FROM sys.objects WHERE [type] = 'P' AND DATEDIFF(dd, [modify_date], GETDATE()) < 10 Above 10 is the number of days. You can change that value according to your need. Below is the output of my screen after running the above script on AdventureWorks DB:
One of my programmers just installed SQL Server 2008 R2 and found the sample database AdventureWorks missing. He was struggling for precise information on how to download the sample database. I would like to share the link from where you can find the AdventureWorks for SQL Server 2008 R2. Download Link AdventureWorks 2008R2 SR1 After installing the sample db, the screenshot:
Today I was working with some Stored procedures and I was in a need where I need to know the created and modified date of stored a procedure. Following is the script which I would like to share which I used to get the desired result: GO SELECT name, create_date, modify_date FROM sys.objects WHERE type = 'P' --AND name = 'sp_dts_getfolder' GO Output at my screen:
Gzip can lead your applications to perform faster since the sizes of the files delivered to client is reduced via gzip algorithm which leads to saving of bandwidth. In ASP.NET applications you can do it via some settings web config. Below is the code which you can put in your web config in system.webServer tag <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compre...
Today I was working with an image and some text which I had to put next to it. The issue which was coming was to vertical align the text to middle of image. <div> <img style="height:50px" src="http://jsfiddle.net/img/logo.png" /> <span style="vertical-align:middle">:( Not coming in the middle.</span> </div> Here is the code which was not working http://jsfid...
In this blog I will show how to cast an int to enum, enum to int and string to enum. Let's make a sample enum: MyEnum.cs namespace Sample.Console { public enum MyEnum { Item1 = 1, Item2 = 2, Item3 = 3, Item4 = 4, Item5 = 5, } } 1. Int to Enum int integerValue = 2; MyEnum myenum = (MyEnum)integerValue; //Output: item2 2. Enum to Int MyEnum myenum = MyEnum.Item3; int integerValue = (int)my...
Yeterday I had a requirement where I needed to find the end of day in datetime. I decided to make extension on datetime to achieve it. Below is the sample code: DateTimeExtension.cs: #region Using Directives using System; #endregion namespace Sample.Console { public static class DateTimeExtension { public static DateTime GetEndOfDay(this DateTime datetime) { return datetime.AddDays(1).Ad...
This message irritates me when I encounter this while debugging my code. I am writing the solution below by which this can be avoided. Step 1: Go to Build >> Configuration Manager and select "Debug " as the option for Active solution configuration. Step 2 : Go to your web project properties >> Build >> General Uncheck the Optimized code checkbox. Step 3: Clean and Rebui...
In this blog I will show how to get selected values of checkboxlist in ASP.NET. The selected value can be get by applying foreach iterator on checkboxlist items and then we can find the selected items. I decided to make an extension to do the same. Below is the code for it: Control Extensions: using System.Collections.ObjectModel; using System.Linq; using System.Web.UI.WebControls; names...
Sometimes it is needed to add some text with linebreaks manually in textarea. It can be done by adding slash r and slash n (\r\n). Below is the sample code to do the same. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <form id="form1" runat="server"> <textarea id="myTextBox" style="width:500px;height:300px"&...
While working with GitHub extensions commit command in VisualStudio, I noticed it was not showing the new files which I added to my solution. This may be some bug of GitExtensions but I was able to resolve this by using the Git's "Git - Pending Changes" command. Instead of using git commit command I went for Git- Pending Changes option. To do the same right click the solution and click G...
Version control is a tool to manage the changes to documents, programs, and other information stored as computer files. It allow us to track what changes we did, revert the changes, do modifications and much more. Many people still have excuses for not using version control, I have listed some of them which I have encountered them saying: I'm the only developer in my company, I don't nee...
I find it handy using shortcut keys for various commands instead of command buttons while using VisualStudio. Today, while working with GIT in Visual Studio, I decided to apply shortcut keys to various commands (Commit, Pull etc.). Below are the steps which I used to do so: Step 1: Go to Tools >> Options Step 2: In Enviornment select keyboard option. Step 3: In Show commands contai...
In this blog I will show you how to extract the text between square brackets, without returning the brackets themselves. I will use REGEX class of in order to do so. Let's assume we have a string "Are you ready for regex [test text] magic?" and we want to extract "test text" from it ie. the text which lies in between the square brackets. Below is the sample code for it: using System.Text...
In this blog I will show how to detect the IIS version using C#. We are going to make use of RegistryKey class which is the encapsulation for registry. Below is the sample code to detect the IIS version: using System; using Microsoft.Win32; namespace Sample { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Version version = GetI...
I was dropping a column today from a table and I got the following error ALTER TABLE DROP COLUMN xxx failed because one or more objects access this column. The complete message which was coming in SQL Server Query Analyzer message pane was: Msg 5074, Level 16, State 1, Line 1 The object 'DF_TestTable_RankId' is dependent on column 'RankId'. Msg 4922, Level 16, State 9, Line 1 ALTER TABLE...
Few minutes back I was working with a table in my DB and I wanted to add a new column with a default value to my existing table. I decided to write a quick blog on the script I used for the same. Syntax: ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE} Example: Let's create an example to do the same. We will first create...
It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.
enter your email address:
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18