Thursday, December 1, 2011

Disable AutoComplete Feature in ASP.NET controls

a) There is an AutoCompleteType in TextBox Property and it will not disable in FireFox

b) in the TextBox set autocomplete="off"

Works both in IE and FireFox

c) the same above, but add as attribute in code behind
txtDate.Attributes.Add("autocomplete", "off");


Tuesday, October 11, 2011

Show Friendly Dates in Pages

Mostly when displaying null dates it appears in the screen as 1/1/0001. To avoid that we can create a readonly property for Example JOINDATESTRING where

public string JoinDateString
{
   get
  {
       if (StartDate == DateTime.MinValue)
      {
           return String.Empty();
      }
     else
    {
       return StartDate.ToString("dd/MM/yyyy");
    }
 }
}

Wednesday, September 14, 2011

Maintain Scroll Position After Postbacks


1- In Web.config, in  page section  declare <pages maintainScrollPositionOnPostBack="true" />, which maintains scroll position for all pages in the site.



2- To set for an individual page, in the page declaration  <%@ Page MaintainScrollPositionOnPostback="true" %> or in the codebehind  set  System.Web.UI.Page.MaintainScrollPositionOnPostBack = true  

Thursday, September 1, 2011

Formatting GridView

To Format the values displayed in GridView:
For BOUNDCOLUMN, use the DataFormatString argument

For TEMPLATECOLUMN, use the second argument of Bind() to format data
Eg:

See complete list of formatting:
Source :http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx


Format character
Description
Example
C or c
Displays numeric values in currency format. You can specify the number of decimal places.
Format: {0:C}
123.456 -> $123.46
Format: {0:C3}
123.456 -> $123.456
D or d
Displays integer values in decimal format. You can specify the number of digits. (Although the type is referred to as "decimal", the numbers are formatted as integers.)
Format: {0:D}
1234 -> 1234
Format: {0:D6}
1234 -> 001234
E or e
Displays numeric values in scientific (exponential) format. You can specify the number of decimal places.
Format: {0:E}
1052.0329112756 -> 1.052033E+003
Format: {0:E2}
-1052.0329112756 -> -1.05e+003
F or f
Displays numeric values in fixed format. You can specify the number of decimal places.
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567
G or g
Displays numeric values in general format (the most compact of either fixed-point or scientific notation). You can specify the number of significant digits.
Format: {0:G}
-123.456 -> -123.456
Format: {0:G2}
-123.456 -> -120
N or n
Displays numeric values in number format (including group separators and optional negative sign). You can specify the number of decimal places.
Format: {0:N}
1234.567 -> 1,234.57
Format: {0:N4}
1234.567 -> 1,234.5670
P or p
Displays numeric values in percent format. You can specify the number of decimal places.
Format: {0:P}
1 -> 100.00%
Format: {0:P1}
.5 -> 50.0%
R or r
Displays Single, Double, or BigInteger values in round-trip format.
Format: {0:R}
123456789.12345678 -> 123456789.12345678
X or x
Displays integer values in hexadecimal format. You can specify the number of digits.
Format: {0:X}
255 -> FF
Format: {0:x4}
255 -> 00ff

d
Short date pattern.
Format: {0:d}
6/15/2009 1:45:30 PM -> 6/15/2009
D
Long date pattern.
Format: {0:D}
6/15/2009 1:45:30 PM ->Monday, June 15, 2009
f
Full date/time pattern (short time).
Format: {0:f}
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45 PM
F
Full date/time pattern (long time).
Format: {0:F}
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45:30 PM
g
General date/time pattern (short time).
Format: {0:g}
6/15/2009 1:45:30 PM -> 6/15/2009 1:45 PM
G
General date/time pattern (long time).
Format: {0:G}
6/15/2009 1:45:30 PM -> 6/15/2009 1:45:30 PM
M or m
Month/day pattern.
Format: {0:M}
6/15/2009 1:45:30 PM -> June 15
O or o
Round-trip date/time pattern.
Format: {0:o}
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000
R or r
RFC1123 pattern (for information, see DateTimeFormatInfo.RFC1123Pattern).
Format: {0:R}
6/15/2009 1:45:30 PM -> Mon, 15 Jun 2009 20:45:30 GMT
s
Sortable date/time pattern.
Format: {0:s}
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30
t
Short time pattern.
Format: {0:t}
6/15/2009 1:45:30 PM -> 1:45 PM
T
Long time pattern.
Format: {0:T}
6/15/2009 1:45:30 PM -> 1:45:30 PM
u
Universal sortable date/time pattern.
Format: {0:u}
6/15/2009 1:45:30 PM -> 2009-06-15 20:45:30Z
U
Universal full date/time pattern.
Format: {0:U}
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 8:45:30 PM
Y or y
Year month pattern.
Format: {0:Y}
6/15/2009 1:45:30 PM -> June, 2009

Wednesday, August 10, 2011

How to get Hidden Value in GridView

Once a column's Visible property is set to Hidden, no longer can we access it, since it returns blank.

To overcome that we can do 4 things
1) Use DATAKEY property and to hidden column ID.
GridView.DataKeys[0].Value.ToString();
 
2) Use TEMPLATE COLUMN and make it visible and access the values using FindControl.
Label lblID = (Label) GridView.Rows[0].FindControl("lblMyId");

3) Using a sylesheet ,set the property display=none, and can get the values.
GridView.Rows[0].Cell[0].Text

4) After databinding, set the visible property of the column.
   GridView.Columns[0].Visible = false;


http://www.dotnetspark.com/kb/1937-how-to-get-hidden-column-value-gridview.aspx

Wednesday, August 3, 2011

Pages Not Displaying CSS/Themes

If we enable authentication in web.config, the master page will not display the CSS styles. The reason, one must login to access all folders and files (including styles and pictures).

To overcome this issue, give permission to the folder containing CSS and pictures in the WEB.CONFIG in the location path and authorization in system.web.


   
     
       
     

   

 


 
   
     
       
     

   

 


Wednesday, July 27, 2011

GridView RowDataBound or RowCommand

The best place to check or bind controls can be done in RowDataBind Event of GridView.

It can also be done in RowCommand event handler, but during postback there are chances data be lost. I was attaching javascript to a button with another value collected from a databound control, and during postback the data collected and passed to javascript was lost.




Thursday, July 21, 2011

Tuesday, July 19, 2011

Configuring Visual Source Safe in Visual Studio IDE

In the Tools -> Options -> Source Control, we should be able to select the Source Control here "Microsoft Visual SourceSafe" or any other provider.

Sometimes the in “Current source control plug-in:”, the only choice available may be “none”. In that case we must manually register the dll.

a) In that case close all Visual Studio instances.

b) Browse to your VSS6\win32 directory and run:
“regsvr32 ssscc.dll”

This would register the library and make VSS 6.0 available in the Visual Studio IDE, when we reopen it.

Monday, July 11, 2011

Using Windows User Role with Active Directory

To use Active Directory permissions in a ASP.NET web application,

1) In WEB.CONFIG, enable windows authentication
< authentication mode="Windows" / >

2) In IIS, enable Windows Authentication and disable Anonymous authentication

Enter Key Default Submit Button

If there is only one button in a WEB FORM, pressing ENTER will enable the default submit button.

If there are more than one buttons in a web form, then we can define the default submit thru DEFAULTBUTTON property either in the FORM  or with an PANEL.

1<form defaultbutton="btnSubmit" id="form1" runat="server"
</form >

2) <panel defaultutton="btnSubmit" id="pnlFirst" runat="server"></panel>

Sunday, July 10, 2011

Connecting MySQL Database with .NET Applications

We can do this many ways,


1) In the MySQL site there is a library to connect to MySQL.
       http://www.mysql.com/products/connector/

Download and install this library. Infact we need only the MySql.Data.dll added as a reference to the project. Then we can work like rest like the ado.net providers with MySQL Connection, MySQLCommand, MySQLDataAdapter and MySQLDataReader

Imports MySql.Data.MySqlClient
Public Sub LoadMySQLDB()

Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet
Dim strSQL As String


myConnection = New MySqlConnection("server=localhost; user id=user1; password=password; database=mydatabase; pooling=false;")


strSQL = "SELECT * FROM mytable;"
myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
myDataSet = New DataSet()
myDataAdapter.Fill(myDataSet, "mytable")

MySQLDataGrid.DataSource = myDataSet
MySQLDataGrid.DataBind()


End Sub

 2) Using OLEDB we can connect to MySQL
3) Using ODBC also we can connect to MySQL.

Friday, July 8, 2011

In GridViewDelete Event KEY values are empty

In the DELETEROWEVENT, the values returned is empty, it appears that e.Keys and e.Values are only populated if gridview.IsBoundUsingDataSourceID.

A possible resolution

int groupId = (int)GridView1.DataKeys[e.RowIndex].Value;