Invalid postback or callback argument ASP.NET

I got this error

I got this error because I was using a ready made html5 template. The problem was duplicate form tag used multiple times in the template. Removing that get rid of the error. To be exact my duplicate form tag was in the master page which was a bit hard to find.

Read More

Looping through gridview in C# always return empty

I had a gridview which was bounded to a datasource (datatable in my case) in code behind in C#. Code was something like this

This was always returning empty (”) no matter which column index I was pointing to. I tried different variations like

but it failed too. After pondering on it for quite a while and still not resolved, I decided to loop through the data source itself, in my case a datatable. That actually worked! That code looks like this

I am still not sure why it will not read the values from GridView in…

Read More

invoke delegate with parameters

Download Ping Example Code (10kb) The following is a simple code to invoke a delegate with parameter. I created this to update label control on the form asynchronously. I did not quite work I was hoping for but the code does pass parameter to the delegate

Read More

RAISERROR and Exceptions

RAISERROR with severity level below 10 are not catched by ADO framework. To fix it simply raise severity level to 10 or above or you can instead use THROW statement which has severity level of 16 by default and will always be catched by the ADO framework (C#). RAISERROR('Your Error Message', 'Severity Level', 'State Level') Set Severity Level to 16 Set State Level to 1 Note that RAISERROR does not stop execution. It is recommend to use THROW statement inst5ead to raise error and stop execution. Does RAISERROR cause Transaction ROLLBACK

Read More

executenonquery returns -1 on success

ExecuteNonQuery is suppose to return the number of rows inserted, updated or deleted but in my case it always return -1 even though the record is successfully added. Found out SET NOCOUNT OFF was missing my in my stored procedure. If you have multiple SQL statements in your stored procedure, initially set it to on by SET NOCOUNT ON which will not count any rows affected. Later to monitor the statement you are actually interested in, set it to OFF. Hope that resolves your problem!

Read More

Spring.NET Constructor Injection Example

The following Console Application (C#) represents Constructor injection using Spring.NET. To use the code in as it is form, create a console application using C# in Visual Studio 2012 and name it Spring4. Copy the content of program file from below. Create another xml file named context.xml and add it to your project. Copy the contents of that file from what I have supplied. Last but not the least, download core from NUGET. You only need the core, you can ignore the rest. Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Spring; using Spring.Context.Support; namespace Spring4 {     class Program     {         /// <summary>         /// This program demonstrates constructor injection using Spring.NET         /// </summary>…

Read More

Accessing Local Resources in MVC

You want to localized your resource or in other words put them in a resource file in the local folder, how do you access it in MVC?   Here is how you will access it     public class Student     {       // Constuctor         public Student()         {             Name = MyStrings.name1;         }         public string Name { get; set; }     } A better way of doing it to put all resources in inside a separate folder and give them proper extension depending on where they will be used. For Example I can use >>LocalizedString >>>>>MyStrings.Resx >>>>>Mystrings.en-GB.Resx The program will automatically pick the right resource depending on the culture setting of the computer. In this…

Read More