Sunday, March 1, 2009

Javascript:Asp.net Radiobuttonlist

Pass the clientID of the radiobutton list and check is it is selected or not.

//Check for selected radio button
function IsRadioSelected(rbClientID)
{

var inputArr = rbClientID.getElementsByTagName("INPUT");
var notselected=0;
for(var count=0;count < inputArr.length ;count++)
{

if(inputArr[count].type =='radio' && inputArr[count].checked==false)
{
notselected++;
}
}
return notselected;
}

Sunday, December 23, 2007

Introduction to C# Generics

The generics is the best thing that has happened to .Net framework 2.0.Generics are type-safe data structures with no real data type.Generics are really very fast and it is very easy to code.In c++ we have the templates which does the samething but it differs in functionality and capabilities.

Why we need the generics?
Object based class was used to accept any type data and the type casting of data type takes times which results in low performance.The next severe problem with the Object-based solution is type safety. Because the compiler lets you cast anything to and from Object, you lose compile-time type safety.

What Are Generics?

Generics allow you to define type-safe classes without compromising type safety, performance, or productivity.

eg:-
public class Gclass<datatype>
{
public void setdata(DataType x)
{
ArrayList arr = new ArrayList();
arr.Add(x);
}
}

use the <> brackets, enclosing a generic type parameter.

//to double to the arraylist
Gclass<double> dX = new Gclass<double>();
dX.setdata(1.22);

//to add integer to the arraylist
Gclass<int>iX = new Gclass<int>();
iX.setdata(1);


//to add string to the arraylist.
Gclass<string> sX = new Gclass<string>();
sX.setdata("Promothash");

This code will help you to implement generics.

Monday, July 23, 2007

Asp.net Cache

Sharing some gyan on the asp.net cache.There are many ways we can maintain state in asp.net and cache is the coolest of all.The main advantage with cache object is that it is specific to single user,subset of users or even all users.It is really very flexible,versatile and performance is better.The cache object can be used both declaratively and programmatically.Adding and deleting data to the cache is very easy.
I will use the insert method because it supports several overloads dependencies, timeouts, priority, and callbacks.
// Add to cache
Cache["testKey"] = "Promothash";

// Read from cache
Response.Write(Cache["testKey"]);

// to add and set duration of cache to 5 seconds
Cache.Insert("testKey","Promothash", null, System.DateTime.Now.AddSeconds(5),
System.Web.Caching.Cache.NoSlidingExpiration);


It can accept one more argument i.e callback function can be excuted when the
cache expires.Create a delegate of the callback function and call it.

//instance of the callback delegate
Callbackcache callBack = new Callbackcache (obj);

Thursday, July 19, 2007

Web service call from Excel


I was facing problems with the web service call from excel and found no help on the web.I have tried googling but landed nowhere.I will show a simple way of calling web service from the excel workbook.

steps1:
Download the Microsoft Office XP Web Services Toolkit2.0
http://www.microsoft.com/downloads/details.aspx?familyid=4922060f-002a-4f5b-af74-978f2cd6c798&displaylang=en

step2:
Open Excel and go to tools->macro->Visual basic editor.

step3:
In the Visual basic editor.goto tools->web service references.As seen in the pic. above.Type the name of the web service and add the web reference.

Step4:
A class module will get created on the vbaproject with some methods such as Class_Initialize(),Class_Terminate(),ServiceErrorHandler(str_Function As String) and with the other methods of the web sevice.

step5:
create a object of the web service and you will have all the mehtods of the web service.
eg:-
Dim wsxls As New clsws_Service
wsxls.wsm_NotificationEngine "promothash@codefasttrack.com"

This seems to be very easy but the problems that may encounter are many like-
issue related to date objects,connection time out problem [-2147221504 error] etc.

Default the connector property of the service is HTTP but it causes problem related to connection time out so to avoid it you must use the "WinInetConnector30" and also set the timeout.
add this code snippet to the Class_Initialize() method to avoid a timeout error[-2147221504].

'declarations
Private sc_Service As SoapClient30
Private Const c_WSDL_URL As String = "http://localhost/wexcel/Service.asmx?wsdl"
Private Const c_SERVICE As String = "Service"
Private Const c_PORT As String = "ServiceSoap"
Private Const c_SERVICE_NAMESPACE As String = "http://tempuri.org/"

Private Sub Class_Initialize()
'*****************************************************************
'This subroutine will be called each time the class is instantiated.
'Creates sc_ComplexTypes as new SoapClient30, and then
'initializes sc_ComplexTypes.mssoapinit2 with WSDL file found in
'http://localhost/wexcel/Service.asmx?wsdl.
'*****************************************************************

Dim str_WSML As String
str_WSML = ""

Set sc_Service = New SoapClient30

sc_Service.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
'Use the proxy server defined in Internet Explorer's LAN settings by
'setting ProxyServer to

sc_Service.ClientProperty("ServerHTTPRequest") = False
sc_Service.ClientProperty("ConnectorProgID") = "MSSOAP.WinInetConnector30"

sc_Service.ConnectorProperty("ProxyServer") = ""
sc_Service.ConnectorProperty("Timeout") = "90000"
'Autodetect proxy settings if Internet Explorer is set to autodetect
'by setting EnableAutoProxy to True
sc_Service.ConnectorProperty("EnableAutoProxy") = True

End Sub

Code Fast Track

This blog will feature the most common problem encountered while developing web projects.It will feature mainly asp.net,c#.net,vb.net,web services,share point and related technologies.I will try to provide the best possible approach for developing web projects.

Thanks
Promothash