Delegate in asp dotnet csharp, with simple example

In csharp, delegates allow programmer to create a variable that ‘points’ to a method.

We know that variables STORES VALUES, similar way deligates STORES POINTER TO METOD.

So we can dynamically or at various time SET DELIGATE in a way that our CALL actually invokes different method.

First step when using a delegate is to define its signature.

So when we use(or point) a delegate variable, we can point only to a method that matches its specific signature.

//declare deligate signature
public delegate int myCustomDeligate(int v1, int v2);

protected void Page_Load(object sender, EventArgs e)
//deligate variable created
myCustomDeligate objPointerToMethod;

objPointerToMethod = AddNumber;
Response.Write(“At time 1 result is=” + objPointerToMethod(3,5) + “<br/>”);

objPointerToMethod = AddNumberV2;    //this is interesting our variable now pointing to second method
Response.Write(“At time 2 result is=” +objPointerToMethod(3, 5) + “<br/>”);


//one method
public int AddNumber(int a1, int a2)
return a1 + a2;

//second method with same signature,but some other logic here
public int AddNumberV2(int b1, int b2)
return b1 + b2 + 10;    //here adding numbers, and adding 10 also to it

Simplest way to calculate first and last day of month and week for specific date in MS Sql Server

I have come up with following few lines that illustrate a way to find first and last day(date) for specified date.

And then given same thing for week.

Declare @SpecifiedDate DateTime;
Set @SpecifiedDate=GETDATE();
Declare @XStart int;
Set @XStart=0;

SELECT @XStart=DATEDIFF(mm,0,@SpecifiedDate)
SELECT DATEADD(mm,@XStart,0) ‘First Day of Specific Month’
SELECT DATEADD(d,-1,DATEADD(mm,@XStart+1,0)) ‘Last Day of Specific Month’

SELECT DATEADD(wk,DATEDIFF(wk,0,@SpecifiedDate ),0) ‘First Day of Week’
SELECT DATEADD(wk,DATEDIFF(wk,0,@SpecifiedDate ),6) ‘Last Day of Week’

Visual Studio 2008 intellisense not working <asp: or stops working for aspx page code view

I just realize importance of ‘intellisense’, as before 2 days visual studio 2008 version, got some issue and when i type TAG for example <asp: , i was not getting immediate menu with suggestion to finish line.

I tried with, Restarting studio and even from Visual Studio Command prompt tried executing command

devenv /ResetSettings

but not got sllution, then from

seen one comment that states that we can clear all files from following two path:

C:\Documents and Settings\<username>\Application Data\Microsoft\VisualStudio\9.0\ReflectedSchemas

C:\Documents and Settings\<username>\Application Data\Microsoft\VisualStudio\9.0\ReflectedTypeLibs

and my Problem Gone. All kind of suggestions are working now in aspx file.

Use of CASE END in ms sql query to get conditional result column.

When we need some conditional output in sql script or query, below syntax will help to achieve.

SELECT Field1,Field2
WHEN  exists(select top 1 Some_Field from Some_Table where [Condition])
THEN ‘OutputA’
ELSE ‘OutputB’
END) as ”AliasName”
From Table1


Read more,

Happy New Year of 2014 to all visitors of my technical blog.

Hello All Readers,

As we all are migrating to new year. I personally feel this new year will give us chance to make new starting for application of new idea in our life and we forgot mistakes and learn from our experience.

And hope god will help us to lead to more bright future and give direction to outcome from trouble.

And as usual technology will go to next step in all phase of life and let we keep moving ahead with it.

Return json format data from code behind of csharp

Review following code snippet to retrive json data in c#.

String strResult = “”;
strResult += “{‘xproducts’: “;
strResult += “[“;
if (dtable.Rows.Count > 0)
for (int i = 0; i < dtable.Rows.Count; i++)
strResult += “{ “;
strResult += “‘xid’:'” + dtable.Rows[i][“Id”].ToString() + “‘, “;
strResult += “‘xname’:'” + dtable.Rows[i][“Name”].ToString() + “‘, “;
strResult += “‘xprice’:'” + dtable.Rows[i][“Price”].ToString() + “‘, “;
strResult += “} “;
if (i != dtable.Rows.Count – 1)
{ strResult += “,”; }

strResult += “]”;
strResult += “}”;

context.Response.ContentType = “text/html”;


Other Post for javascript:

Show current date using Javascript in web browser(Client side date in web browser)

For client side scripting,

Go through following lines to product date in DD/MM/YYYY format:

var objToday = new Date();
var dd = objToday.getDate();
var mm = objToday.getMonth() + 1;  //January is 0
var yyyy = objToday.getFullYear();

if (dd < 10) { dd = ‘0’ + dd }
if (mm < 10) { mm = ‘0’ + mm }

var strToday = dd + ‘/’ + mm + ‘/’ + yyyy;

alert(strToday);       // will show like ’17/07/2013′