Thursday, September 18, 2014

Custom CSS style for AJAX AutoComplete Extender



 <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"

     ...

     ...

     CompletionListCssClass="completionListCSS"

     CompletionListItemCssClass="listItemCSS"

     CompletionListHighlightedItemCssClass="itemHighlightedCSS">  

 </asp:AutoCompleteExtender>


 CSS style:

<style type="text/css">

        .completionListCSS {

        border:solid 1px Gray;

        margin:0px;

        padding:3px;

        height: 120px;

        overflow:auto;

        background-color: #FFFFFF;   

        }

        .listItemCSS {

        color: #191919;

        }

        .itemHighlightedCSS {

        background-color: #ADD6FF;     

        }

    </style>

Custom CSS style for AJAX AutoComplete Extender

Monday, July 14, 2014

Validation of viewstate MAC failed





Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.




The first option is to set the EnableViewStateMac to false in the web.config. This is an attribute of the Page tag. You also have the option to set the EnableViewStateMac to false at page level. The only drawback  with this option is that you need to do this for all page across the application.
In web.config

<pages enableViewStateMac="false">
.
.
</pages>

At page level
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default"
 EnableViewStateMac="false" %>


Other option is to specify your own value for encryption and decryption key in the web.config . Now this key will be same across the servers.
Both the option will work perfectly, but it is always advisable to go with specifying the custom key for encryption and decryption in web.config. This is because when you set the EnableViewStateMac value to false you expose your application to security threats. This is because validation of view state will not happen in this case.

<machineKey validationKey="<encryptionkey>" decryptionKey="<decryptionkey>" validation="SHA1" decryption="Auto"/>

Machine key Generate from here -  
http://www.a2zmenu.com/utility/Machine-Key-Generator.aspx

Wednesday, September 4, 2013

copy an array to hidden field and get back to array in javascript


   

Values are only strings or integers and a seperator(',') should not present in an array.


                        document.getElementById("hiddenfield").value = oldArray.join(",");

To retreive that array back

                          NewArray = document.getElementById("hiddenfield").value.split(",");

Monday, May 6, 2013

detect browser in web application using Jquery and ASP.Net C#

Using Jquery we can detect current browser and their version.


$(document).ready(function() {
   if ($.browser.mozilla && $.browser.version >= "2.0" ){
    alert('Mozilla above 1.9');
   }
  
   if( $.browser.safari ){
    alert('Safari');
   }
 
   if( $.browser.opera){
    alert('Opera');
   }
 
   if ($.browser.msie && $.browser.version <= 6 ){
    alert('IE 6 or below version');
   }
 
   if ($.browser.msie && $.browser.version > 6){
    alert('IE above 6');
   }
 });


Using ASP.NET

 Response.Write("Request.Browser.Type--------------------->" + Request.Browser.Type);

                Response.Write("<br/>Request.Browser.Version  ----------->   " + Request.Browser.Version);

                Response.Write("<br/>Request.Browser.W3CDomVersion------->" + Request.Browser.W3CDomVersion);

                Response.Write("<br/>Request.Browser.Browser------------->" + Request.Browser.Browser);

                Response.Write("<br/>Request.Browser.Browsers------------>" + Request.Browser.Browsers);

                Response.Write("<br/>Request.Browser.MajorVersion-------->" + Request.Browser.MajorVersion);

OUTPUT

Request.Browser.Type--------------------->IE10
Request.Browser.Version -----------> 10.0
Request.Browser.W3CDomVersion------->1.0
Request.Browser.Browser------------->IE
Request.Browser.Browsers------------>System.Collections.ArrayList
Request.Browser.MajorVersion-------->10
 

Monday, March 11, 2013

Serach Column in Existing table in Database and alter table

/*ADD one column "ColumnName" in table TableName */
 
 IF NOT EXISTS  SELECT 'X' FROM INFORMATION_SCHEMA.COLUMNS COLUMNS, INFORMATION_SCHEMA.TABLES TABLES

WHERE
COLUMNS.TABLE_NAME=TABLES.TABLE_NAME AND UPPER(COLUMNS.COLUMN_NAME)=UPPER('ColumnName') AND UPPER(TABLES.TABLE_NAME) = UPPER('TableName'))

BEGIN

ALTER TABLE  TableName    ADD ColumnName   INT Default(0)

END

GO

Wednesday, February 13, 2013

How can combine multiple column as a one column in SQL SERVER?


Suppose there is a table Employee and recordset as



EmpID
Name
Sal
1
PQR
1000
2
XYZ
2000
3
ABC
3000


And aspected Result as



FieldName
Value
EmpID
1
Name
PQR
Sal
1000
EmpID
2
Name
XYZ
Sal
2000
EmpID
3
Name
ABC
Sal
3000




Query -

SELECT  FieldName, Value
FROM
(
    SELECT CAST(EmpID AS VARCHAR(10))EmpID,
    CAST(name AS VARCHAR(10)) Name,
    CAST(sal AS VARCHAR(10)) Sal
    FROM Employee
)x
UNPIVOT
(
Value
FOR FieldName in (EmpID,Name,Sal)
)y



Sunday, March 4, 2012

Serialization/Deserialization in .NET

Serialization

Serialization is the process of taking an object and converting it to a format in which it can be transported across a network or persisted to a storage location. The storage location could be as simple as using a file or a database. The serialized format contains the object's state information.

Deserialization
Deserialization is the process of using the serialized state information to reconstruct the object from the serialized state to its original state.
 In essence, the process of serialization allows an object to be serialized, shipped across the network for remoting or persisted in a storage location such as the ASP.NET cache, and then be reconstructed for use at a later point in time.


Serialization Formats

There are three formats provided by the Microsoft .NET framework to which objects can be serialized. The formats are Binary, SOAP, and XML. The format is controlled based upon what object is used to perform the serialization. The XML format is produced by using the System.Xml.Serialization.XmlSerializer class. The SOAP and binary formats are produced by using classes under the System.Runtime.Serialization.Formatters namespace.
There are subtle differences among the serialized formats. The binary-based format is the most compact and light of the three formats. The XML formatter only serializes public fields and properties, while binary and SOAP do not adhere to that limitation.