Sunday, March 21, 2010

Error: ASP.NET Ajax client-side framework failed to load. OR 'Sys' is undefined.

Error: ASP.NET Ajax client-side framework failed to load. OR 'Sys' is undefined. in VS 2008

Cause:

I got this error very first time when I tried to use AJAX ScriptManager object using VS2008.

I was tring to registred script using ScriptManager like below


protected void Button1_Click(object sender, EventArgs e)

{

ScriptManager.RegisterStartupScript(

this,this.GetType(),"script","alert('Hi');",true);

}

Solution:

I found there are two way to solve this error

1) You need to add httpHandlers into the web.config below "compilation" tag

Code:

<!--Ajax -->

<httpHandlers>

<remove verb="*" path="*.asmx"/>

<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/>

</httpHandlers>

<compilation debug="true">

2) You can solve this error by using RegisterAsyncPostBackControl method

Using beolw code button control will not have any page refresh like a client control.

Code:

protected void Page_Load(object sender, EventArgs e)

{

// register the Button1 control as one that can cause partial postbacks.

ScriptManager1.RegisterAsyncPostBackControl(Button1);

}

Note: I may not get this error in latest version/patch of VS2008.

Wednesday, March 10, 2010

Combo box Auto Complete Property in C# and VB using .NET

Combo box Auto Complete Property in C# and VB using .NET

When you have a requirement for combo box control like: when user types some text/number then combo box should display/select value as per user typing the characters from keyboard.

Ex: If Combo Box having following items (Source code load the combo box value)

ComboBox1.Items.Add("ABC123")

ComboBox1.Items.Add("AABC123")

ComboBox1.Items.Add("AAABC123")

ComboBox1.Items.Add("AAAABC123")

ComboBox1.Items.Add("CCCEF123")

ComboBox1.Items.Add("1123ABC")

ComboBox1.Items.Add("2234BCD")

ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

and requirement is when user type in the combo box the relative text should display

Ex: When user type "A" then combo box should select "ABC123" value from the list

When user type "AA" then combo box should select "AABCD123" value from the list

When user type "AAA" then combo box should select "AAABC123" value from the list

etc.

To achieve above requirements, very simple in .NET to use "ComboBox1.AutoCompleteMode" property, it has 4 mode and default is "None"

1) AutoCompleteMode.Append
This Mode will append the value as user type the character one by one and select the nearest value in the combo box
2) AutoCompleteMode.Suggest
This Mode will select the nearest value in the combo box when user type ONLY first characher in the combo box and will open (Drop) the combo box to suggest the other nearest possible value present in the combo box
Ex:
3) AutoCompleteMode.SuggestAppend
This Mode will append the value as user type the characters one by one and select the nearest value in the combo box and also will open (Drop) the combo box to suggest the other nearest possible value present in the combo box
4) AutoCompleteMode.None (Default)
This Mode will select the nearest value in the combo box when user type ONLY first characher in the combo box

Tuesday, March 09, 2010

How to create ASP.NET Web Parts for Windows SharePoint Services 3.0

How to create ASP.NET Web Parts for Windows SharePoint Services 3.0


Good video to learn how to create web part using ASP.net 3.0.
Get idea about web part and how to use in Share Point Service 3.0.


Full screen

Saturday, March 06, 2010

What is “unsafe” Keyword in C#.NET

What is "unsafe" Keyword in C#.NET

In C# the value can be directly referenced to a variable, so there is no need of pointer. Use of pointer sometime crashes the application. But C# supports pointer and we can use pointer in C#.

The use of pointer in C# is defined as an unsafe code. So if we want to use pointer in C# the pointer must be present in the body of unsafe declaration. But pointer does not come under garbage collection.

Example:-

unsafe

{

int firstVariable;

int* secondPointerVariable;

firstVariable = 25;

secondPointerVariable = &firstVariable;

Console.WriteLine("secondPointerVariable = {0}", secondPointerVariable);

//returns secondPointerVariable = 25

}


Note: you may get compilation error ("Unsafe code may only appear if compiling with /unsafe") while compiling the above code.

If you' are compiling from the command line then include the /unsafe switch as the error suggests.
If you're compiling from Visual Studio, then look in your project's properties and, under the build tab, check the 'Allow unsafe code' box. It should work fine.

How to make an application offline in ASP.NET

How to make an application offline in ASP.NET

Microsoft's Internet Information Services (IIS) web server software is used to make an application offline. The IIS is instructed to route all incoming requests for the web site to another URL automatically.

Steps for application configuration:

  • From IIS manager -> right-click on the application -> choose Properties.
  • Choose Virtual Directory tab and indicate that the content for this application should come from "A redirection to a URL."
  • Then enter the same URL to redirect in "Redirect to".
  • Check the box "The exact URL entered above.

Read more way to do the same.

http://aspalliance.com/1666_How_to_Make_an_Application_Offline_in_ASPNET_20.all

Web Service Vs WCF (Window Communication Foundation)

Web Service Vs WCF (Window Communication Foundation)

WCF is a set of .NET Framework-based technologies for building and running services. WCF is the next step in the evolutionary path that started with COM, COM+, and MSMQ, and continues through .NET Remoting, ASMX, System.Messaging, and .NET Enterprise Services. WCF combines these technologies and offers a unified programming model for developing services using any CLR-compliant language.


Feature

ASP.NET Web Service

WCF

Performance

Slower compared to WCF

The main benifit of the design of the DataContractSerializer is better performance over XML serialization

File Extension

File extention is asmx

File extension is .svc

Data Transformation

To and from Data Transition is done through XML Serializer

DataContractSerializer is used for data transition

Webmethods vs DataContract Attributes

ASP.NET WebService uses Webmethods to to translate .NET FW types in to XML.

The WCF uses the DataContractAttribute and DataMemeberAttribute to translate .NET FW types in to XML.

Limitations

Only Public fields or Properties of .NET types can be translated into XML.Only the classes which implement IEnumerable interface, ICollection interface can be serializable

Public/Private fields or properties of .NET types can be translated

IDictionary Interface class

Classes that implement the IDictionary interface, such as Hash table can not be serialized.

The DataContractSerializer can translate the Hash Table into XML. Hence using WCF we can even translate HashTable into XML

Know which fields /properties

XMLSerialization does not indicate the which fields or properties of the type are serialized into XML

DataCotratSerializer Explicitly shows the which fields or properties are serialized into XML

Exception handling

In ASP.NET Web services, Unhandled exceptions are returned to the client as SOAP faults.

In WCF Services, unhandled exceptions are not returned to clients as SOAP faults. A configuration setting is provided to have the unhandled exceptions returned to clients for the purpose of debugging.

Example

[WebService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string Demo(string strDemog)
{
return strDemo;

}
}

[ServiceContract]
public interface ITest
{
[OperationContract]
string Demo (string strDemo);
}
public class Service : ITest
{
public string Demo(string strDemo)
{
return strDemo;
}
}


Learn more about WCF
http://www.xvpj.net/2008/03/08/wcf-step-by-step-tutorial/
http://www.15seconds.com/Issue/061130.htm