Sunday, November 20, 2011

How to open a page in a new window.

How to open a page in a new window. Easy. Here is how:

ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( 'http://www.google.com', null, 'height=200,width=400,status=yes,toolbar=no,menubar=no,location=no' );", true);


or :

Monday, October 31, 2011

Wednesday, September 21, 2011

Comfirm for delete button

Simply making a confirm message for a delete button.

All you have to do is add this  onclientclick="return confirm('Are you sure you want to Delete this Apointment ?');"
For example :


       <asp:Button ID="Button2"
                    runat="server"
                    Text="Delete"    onclick="Button2_Click"
                    onclientclick="return confirm('Are you sure you want to Delete this Apointment ?');" />
Simple?

Tuesday, August 16, 2011

SELECT THE LATEST DATE RECORDS

Table REFILLED:
PatientID Date_refilled
3 7/6/2011
3 7/6/2011
3 2/15/2011
1 8/11/2011
1 8/2/2011
1 8//7/2011

Question: How to select the all latest date records of a patient

Output should be :
PatientID Date_refilled

1 8/11/2011
3 7/6/2011
3 7/6/2011


Here is the select command :

SELECT PatientID, date_refilled
FROM REFILLED AS t
WHERE (date_refilled =
(SELECT MAX(date_refilled) AS Expr1
FROM REFILLED
WHERE (PatientID = t.PatientID)))
ORDER BY PatientID

Tuesday, June 28, 2011

FreeTextBox Control

In this article I will explain you how easy it is to add an open source HTML editor in your ASP .Net application. If you are creating your own content management system and you want your user to give capabilities to express their thoughts in formatted way, FreTextBox is your available open source solution. If you are creating a discussion forum and want your users to give high end content editing capabilities this is a very good option.

Step - 1

So very first thing that you have to do is to get latest version of FreeTextBox editor from its web site http://freetextbox.com/download/ Once you download the latest you will find the latest assembly for using in your application. Get this dll file copy this file to locally to your project folder inside Bin folder. Once this is done you are half way done.

Step - 2

Next thing is to add a reference to your web.config file. Simply add following line in your web.config file inside <httpHandlers> section.

<add verb="GET" path="FtbWebResource.axd" type="FreeTextBoxControls.AssemblyResourceHandler, FreeTextBox" />

Step - 3

Next thing is to add a reference to your web page where you want to use this editor. Simply add following line to your web page after page directive.

<%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>

Step - 4

Now before you actually add this control on your page and start using it a very important task has to be done is adding a support folder to your application. Usually when you download the source from the link above you will get a folder named aspnet_client/ FreeTextBox. Simply copy the FreeTextBox folder inside your application. Make sure you know the exact path where you are placing this folder as we will use it while we actually declare this control on our page. This folder contains supporting JavaScript files and images files and css files.

Step - 5

And the last step is to declare this control on your page and start using it. It can be done by code below.

<FTB:FreeTextBox ID="FreeTextBox1" Focus="true" SupportFolder="FreeTextBox/"

JavaScriptLocation="ExternalFile" ButtonImagesLocation="ExternalFile" ToolbarImagesLocation="ExternalFile"

ToolbarStyleConfiguration="OfficeXP" ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,

FontForeColorPicker,FontBackColorsMenu,FontBackColorPicker|Bold,

Italic,Underline,Strikethrough,Superscript,Subscript,RemoveFormat|JustifyLeft,

JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;

CreateLink,Unlink,InsertImage|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save|SymbolsMenu,

StylesMenu,InsertHtmlMenu|InsertRule,InsertDate,InsertTime|InsertTable,EditTable;

InsertTableRowAfter,InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,

DeleteTableColumn|InsertForm,InsertTextBox,InsertTextArea,InsertRadioButton,

InsertCheckBox,InsertDropDownList,InsertButton|InsertDiv,EditStyle,

InsertImageFromGallery,Preview,SelectAll,WordClean,NetSpell"

runat="Server" GutterBackColor="red" DesignModeCss="designmode.css" ButtonSet="Office2000" />

And that’s it, your cool and powerful HTML editor is ready in your users’ service. Before we close this topic let’s discuss how we can use this control to store the content to your database, catch while storing and accessing these value.

The value of your editor can be easily access using line below.

Output.Text = FreeTextBox1.Text;

Here the Output is the literal control which can easily decode your values from HTML editor and show your users for just viewing purpose. This control can be defined as below. You can also store this data into database and retrieve back upon user’s request on to similar literal control.

<asp:Literal id="Output" runat="server" />

Catch:-

Now when you actually start using this you will get an error as below.

A potentially dangerous Request.Form value was detected. This screen will look something like below.

Simply add this to your page directive and this error will disappear

ValidateRequest="false".

This is what you have to do to use a fully functional HTML editor in your web application.

Thanks you.


Source : http://www.a2zdotnet.com/View.aspx?Id=28

Source :

Sunday, May 1, 2011

How to Find Out What Account ASP.NET is Running Under

You can find out what account your ASP.NET application is running under by simply executing the below code :
Response.Write(Environment.UserName)

Wednesday, April 13, 2011

String Format for DateTime [C#]

String Format for DateTime [C#]

This example shows how to format DateTime using String.Format method. All formatting can be done also using DateTime.ToString method.

Custom DateTime Formatting

There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed),t (P.M or A.M) and z (time zone).

Following examples demonstrate how are the format specifiers rewritten to the output.

[C#]
// create date time 2008-03-09 16:05:07.123 
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);  
String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year 
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month 
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day 
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24 
String.Format("{0:m mm}",          dt);  // "5 05"            minute 
String.Format("{0:s ss}",          dt);  // "7 07"            second 
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction 
String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes 
String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M. 
String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone  

You can use also date separator / (slash) and time sepatator : (colon). These characters will be rewritten to characters defined in the current DateTimeForma­tInfo.DateSepa­rator andDateTimeForma­tInfo.TimeSepa­rator.

[C#]
// date separator in german culture is "." (so "/" changes to ".") 
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9/3/2008 16:05:07" - english (en-US) 
String.Format("{0:d/M/yyyy HH:mm:ss}", dt); // "9.3.2008 16:05:07" - german (de-DE)  

Here are some examples of custom date and time formatting:

[C#]
// month/day numbers without/with leading zeroes 
String.Format("{0:M/d/yyyy}", dt);            // "3/9/2008" 
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"  // day/month names 
String.Format("{0:ddd, MMM d, yyyy}", dt);    // "Sun, Mar 9, 2008" 
String.Format("{0:dddd, MMMM d, yyyy}", dt);  // "Sunday, March 9, 2008" /  
String.Format("{0:MM/dd/yy}", dt);            // "03/09/08" 
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"  

Standard DateTime Formatting

In DateTimeForma­tInfo there are defined standard patterns for the current culture. For example property ShortTimePattern is string that contains value h:mm tt for en-US culture and value HH:mm for de-DE culture.

Following table shows patterns defined in DateTimeForma­tInfo and their values for en-US culture. First column contains format specifiers for the String.Format method.

SpecifierDateTimeFormatInfo propertyPattern value (for en-US culture)
tShortTimePatternh:mm tt
dShortDatePatternM/d/yyyy
TLongTimePatternh:mm:ss tt
DLongDatePatterndddd, MMMM dd, yyyy
f(combination of D and t)dddd, MMMM dd, yyyy h:mm tt
FFullDateTimePatterndddd, MMMM dd, yyyy h:mm:ss tt
g(combination of d and t)M/d/yyyy h:mm tt
G(combination of d and T)M/d/yyyy h:mm:ss tt
m, MMonthDayPatternMMMM dd
y, YYearMonthPatternMMMM, yyyy
r, RRFC1123Patternddd, dd MMM yyyy HH':'mm':'ss 'GMT' (*)
sSortableDateTi­mePatternyyyy'-'MM'-'dd'T'HH':'mm':'ss (*)
uUniversalSorta­bleDateTimePat­ternyyyy'-'MM'-'dd HH':'mm':'ss'Z' (*)
(*) = culture independent

Following examples show usage of standard format specifiers in String.Format method and the resulting output.

[C#]
String.Format("{0:t}", dt);  // "4:05 PM"                         ShortTime 
String.Format("{0:d}", dt);  // "3/9/2008"                        ShortDate 
String.Format("{0:T}", dt);  // "4:05:07 PM"                      LongTime 
String.Format("{0:D}", dt);  // "Sunday, March 09, 2008"          LongDate
String.Format("{0:f}", dt);  // "Sunday, March 09, 2008 4:05 PM"  LongDate+ShortTime 
String.Format("{0:F}", dt);  // "Sunday, March 09, 2008 4:05:07 PM" FullDateTime 
String.Format("{0:g}", dt);  // "3/9/2008 4:05 PM"             ShortDate+ShortTime 
String.Format("{0:G}", dt);  // "3/9/2008 4:05:07 PM"             ShortDate+LongTime 
String.Format("{0:m}", dt);  // "March 09"                        MonthDay 
String.Format("{0:y}", dt);  // "March, 2008"                     YearMonth 
String.Format("{0:r}", dt);  // "Sun, 09 Mar 2008 16:05:07 GMT"   RFC1123 
String.Format("{0:s}", dt);  // "2008-03-09T16:05:07"             SortableDateTime 
String.Format("{0:u}", dt);  // "2008-03-09 16:05:07Z"            UniversalSortableDateTime 

Wednesday, April 6, 2011

Maintain the scroll position for the web page

To maintain the scroll position for the large web page you can use on of these methods :

1- use Web.config page section <pages maintainScrollPositionOnPostBack="true" />

: this will maintains the scroll positions for all the web site pages.

2- in the page declaration <%@ Page MaintainScrollPositionOnPostback="true" %> : this will maintains the scroll position for this page only.

3- programmatically from code behindSystem.Web.UI.Page.MaintainScrollPositionOnPostBack = true; : this will maintains the scroll position for this page only (the same as page declration).


Tuesday, April 5, 2011

Count column in GridView

Sometime , You want to add a column to show the count of records in a gridview. It is simple,
just add a templatefield and add this in :
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>