Friday, December 11, 2015

ASP.NET5 is CROSS PLATFORM!!!

Hi All,

I am back here after a long break ....
Last few years had a chance to work on platform independent technologies like LAMP.
Now this news looks like I need focus back on to .NET ...

ASP.NET 5 is CROSS PLATFORM !!!

ASP.NET 5 is a significant redesign of ASP.NET.
 ASP.NET, MVC, and Web Pages are now merged into a single framework named MVC 6.
It includes the following features:
  • Linux support
  • OSX support
  • Node.js support
  • AngularJS support
  • Tag Helpers
  • View Components
  • Web API
  • GruntJS support
  • Bower support
  • No Visual Basic
  • No Web Forms
See below ...

Tuesday, June 30, 2009

Pattern to fill collections for Object-relational mapping in C#.Net

Hi,
Now with generics creating collections is very easy in .Net.
but filling the collections with data has been a repeated coding job always.
This made me write this pattern by which we can create a new collection class in just couple of lines. This uses the same filling method used by ORM (Object-relational mapping ) object.



using System;
using System.Collections.Generic;
using System.Data;

namespace Prashant.Components.DBDataLister
{

// define a delegate for standard database retrival methods
public delegate IDataReader DBSelect(SearchParams Criteria);

// Interface of ORM
public interface IDBObject
{
void FillProperties(IDataReader dr);
}

// Interface of ORM collection
public interface IDBObjectList : System.Collections.IList
{
IDBObject NewItem();
}

// This class standizes the parameters for database retrival methods
public class SearchParams : Dictionary < string, string >
{
}

// The Collection filler class
internal static class DataLister
{

// The Fill method: Gets the data from db and fills the collection
// Paramters: 1) The List to fill
2) The method to get the data
3) Criteria for the filtering the data

internal static IDBObjectList FillData(IDBObjectList List,
DBSelect DoSelect, SearchParams Criteria)
{
IDataReader dr = DoSelect(Criteria);
while (dr.Read())
{
IDBObject objArr = List.NewItem();
objArr.FillProperties(dr);
List.Add(objArr);
}
return List;
}
}

}
// End



Now lets see how to use this in the sample below


using System;
using System.Collections.Generic;
using System.Data;
using Prashant.Components.DBDataLister;

namespace TestProj.Components
{
// A sample ORM class - for the database table Orders
public class Order : IDBObject // To enforce the FillProperties method
{
public string OrderNumber
{ get; private set; }
public string OrderDate
{ get; private set; }
public string Customer
{ get; private set; }

public void FillProperties(IDataReader dr)
{
OrderNumber = (string)dr["OrderNumber"];
OrderDate = (string)dr["OrderDate"];
Customer = (string)dr["Customer"];
}
}
// Data service Class/methods for the ORM
public class OrderService
{
public static IDataReader getOrderData(SearchParams Criteria)
{ // db retivial code goes here ...full code omited
IDataReader dr = DataService.getOrderList(.....);
return dr;
}
}


// This is the collection for Orders

public class OrderList : List < Order >, IDBObjectList
{
public IDBObject NewItem()
{
return (new Order());
}

// Returns the filled collection
public static OrderList getList(SearchParams Criteria)
{
return ((OrderList)DataLister.FillData(new OrderList(),
new DBSelect(OrderService.getOrderData), Criteria));

}

}


}


See the "OrderList" class sample given .
Your gridview cab be bound by

grv.Datasource = OrderList.getList(Criteria);

Friday, February 29, 2008

Handling page refresh (F5) in ASP.NET post backs

Handling page refresh (F5) on post backs is one of the biggest problem for many web applications.Usually we used the simplest solution by redirecting to the same page after the action, but not always usefull.

In the previous post we saw how to handle a multiple user clicks on the same button.
but still user can overdo things by page refresh (F5).

I use a header user control in all my applications which I found is the best place to handle this. The theory is F5 will post a older viewstate so if we have anything to compare we can skip the action from being perfomed once again.

The below code in .NET2.0 goes well with IE.
Insert it in your page or some common header/banner control


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["PostID"] = "1001";
ViewState["PostID"] = Session["PostID"].ToString();
}
}

public bool IsValidPost()
{
if (ViewState["PostID"].ToString()
== Session["PostID"].ToString())
{
Session["PostID"] =
(Convert.ToInt16(Session["PostID"]) + 1).ToString();

ViewState["PostID"] = Session["PostID"].ToString();

return true;
}
else
{
ViewState["PostID"] =
Session["PostID"].ToString();

return false;
}

}



Now in your button click verify if the postback is real button click


public void ActionEvent(object sender, CommandEventArgs e)
{
if (IsValidPost())
{
DoPocessing();
}
}

How to avoid multiple button clicks while post back in ASP.NET

Many time we face the issue how to prevent user from clicking the same button before completing the post back.

A simple java script can be added for this. this will change the text of button and verify. A Dot Net 2.0 example given below


< asp:Button ID="btnAction" runat="server"
OnCommand="ActionEvent"
OnClientClick="
{
var res=this.value=='Processing...'?false:true;
this.value='Processing...';
return res;
}"
Text="Do Action" Width="125px" />

The text of button is changed to 'Processing...' so that the user even knoWS something is going on and even if he clicks it will not post back as our client script returns false if the caption is 'Processing...'.

Monday, September 25, 2006

XSD to C# class or VB.net class

While working with biztalk using web services i found this as a must to have tool.
The XSD.exe from microsoft can be used for this.

The Sample Code Generator (XSDObjectGen) tool takes an XSD schema as input and generates sample code showing how to mark up C# and VB.Net classes so that when serialized with the XML serializer, the resulting XML will be valid according to the original schema.

Download link from microsoft

Friday, August 18, 2006

Accessing Request or Session objects from class modules

When we need to use a request object from another class modules we have to use the
HttpContext.Current object. This contains all the state informations like request, session, Server, Respose etc.
Eg:
string r = HttpContext.Current.Request["MyParam"].ToString();
string s = HttpContext.Current.Session["MySessionVar"].ToString();

Note: Add "using System.Web" to the header.

Wraping Session to Gobal Session Class


using System;
using System.Web;

namespace MyApp
{
public class SessionGlobal
{

private const string _AccountNo = "_AccountNo";

// Set to default Values
public static void Clear()
{

HttpContext.Current.Session[_AccountNo]="";

}

private static string getSessionVar(string key)
{
if(HttpContext.Current.Session[key]!=null)
return HttpContext.Current.
Session[key].ToString();
else
return "";

}

public static string AccountNo
{
get
{
return getSessionVar(_AccountNo);
}
set
{
HttpContext.Current.Session[_AccountNo]=value;
}
}

public static string UserID
{
get
{
return HttpContext.Current.
Request.ServerVariables["AUTH_USER"];
}

}

}
}

Software requirements for a complete installation of BizTalk Server 2006

The minimum software requirements for a complete installation of BizTalk Server 2006 on a single computer:

  • Windows Server 2003 with Service Pack 1
  • Microsoft Office Excel 2003 and InfoPath 2003 with Service Pack 2
  • Microsoft Visual Studio 2005 with Microsoft Visual C# .NET
  • Microsoft SQL Server 2005 or Microsoft SQL Server 2000 with Service Pack 4
  • Microsoft SQL Server 2005 Analysis Services or Microsoft SQL Server 2000 Analysis Services with Service Pack 4
  • Microsoft SQL Server 2005 Notification Services or Microsoft SQL Server 2000
  • Notification Services 2.0 with Service Pack 1
  • Microsoft Windows SharePoint Services 2.0 with Service Pack 2

Tuesday, February 21, 2006

Create a simple Serial/row No column in Datagrid/DataList

A very simple way to create Serial/row No column in Datagrid/DataList

create a variable in the code behind


protected int i=1;

Now in the Datagrid/DataList add a TemplateColumn with data bound to the variable



<asp:TemplateColumn HeaderText="SL#">
<ItemTemplate>
<%# i++ %>
</ItemTemplate>
</asp:TemplateColumn>


This may not be usefull for item identification when used in sortable grid