logs of my work and digital life
Posts tagged web development
ELMAH: Error Logging Modules and Handlers
Jun 24th
Today from a blog I discovered this project called ELMAH: Error Logging Modules and Handlers by the name you can guessed by now what it does
and let me tell you it does it very well. After reading a tutorial ELMAH plugged into my asp.net 3.5 test project and working good. I really liked it and thinking to use it into my future projects.
If you need a serious error logging utiliy download ELMAH now.
BLL – Business layer with Linq
Jun 8th
Hello guys,
This is my first Bll class that is using linq and returning objects to presentation layer. Main data component class is ItemsDT which contain another skeleton class “ItemGridView” for custom view of items data table. “ItemGridView” contains basically have the fields that i want to show in my presentation layer. Note that items datatable has many column which can be reterived by calling AllItems() method.
If you just want to list all the methods into your table that is also included into your linq to sql file then you can set your method return type to list collection of the type that specified in dbml file (linq to sql). For example if you add items table into your linq to sql you will have a new type or class called Item. From your linq code you can return all the rows into the table as objects. Now these objects you can have as list collection of type Items so your method can return List<Items> and this return list will bind to any databound control like grid view with ease.
Problem arises if someone say only show selective columns then if you try to select few colums you will see visual studio provding you hint that objects return from the linq query will be of annonymous type. So to tackle this you have two options either spicy your return varriable of object type or write a skelton class that have all those columns you want to have from your datable. Below is the code with skelton class approch its easy to guess skelton class will define a type and visual studio will not alert anymore by saying your objects are of annonymous type.
{
[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
public static List<Items> AllItems()
{
DBDataContext db = new DBDataContext();
return (from t in db.Items select t).ToList<Items>();
}
public class ItemGridView
{
public int itemID { get; set; }
public string itemName { get; set; }
public string itemgroupName { get; set; }
}
[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
public static List<ItemGridView> ListSubGroups_Admin()
{
return (from t in AllItems() select new ItemGridView {
itemID = t.sgID,
itemName = t.sgName,
itemgroupName = t.Group.gName
}).ToList<ItemGridView>();
}
Sql Data Srouce Control Updating Data From Database
Jul 17th
hey guyz finally we have to learn how to update our tables in database so only for you guys here is my sample code
string giftId = GridView1.SelectedRow.Cells[0].Text.ToString(); //getting an id
SqlDataSource myDbSource = new SqlDataSource();
myDbSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//myDbSource.InsertCommand = “update gifts set giftActivate=1 where giftId=” + Entrydate + “)”;
myDbSource.UpdateCommand = “update gifts set giftActivate=’1′ where giftId=” + giftId;
myDbSource.ProviderName = “System.Data.SqlClient”;
myDbSource.Update();
Well this code set giftActive flag to 1 for all the rows matched with giftid value.
Sql Data Srouce Control Deleting Data From Database
Jul 17th
Hey guyz today i will show you how to fire delete query by using our beloved control sqldatasource.
Here is the code
SqlDataSource myDbSource22 = new SqlDataSource();
myDbSource22.ConnectionString = ConfigurationManager.ConnectionStrings["lalConnectionString"].ConnectionString;
myDbSource22.ProviderName = “System.Data.SqlClient”;
myDbSource22.DeleteCommand = “delete from ProductsGroups where pid = ” + productId;
myDbSource22.Delete();
All it does it deletes all the rows for a given productID from table productgroups. Simple right
Sql Data Srouce Control Inserting Data Into Database
Jul 17th
hey guyz how are you ??
Me back with my sqldatasource series. Today i will show you how to fire insert query using sqldatasource control into code behind i am using c#.
Below is the sample code UserID is the parameter passing into a function as an argument.
DateTime Entrydate = DateTime.Today;
SqlDataSource myDbSource = new SqlDataSource();
myDbSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
myDbSource.InsertCommand = “insert into tbl_invoices (user,Entrydate) values (” + UserID + “,’” + Entrydate + “‘)”;
myDbSource.ProviderName = “System.Data.SqlClient”;
myDbSource.Insert();
myDbSource.SelectCommand = “SELECT IDENT_CURRENT(‘tbl_invoices’)”;
DataView dv = (DataView)myDbSource.Select(new DataSourceSelectArguments());
DataTable dt = dv.Table;
string invNumber = dt.Rows[0][0].ToString();
return invNumber.ToString();
//return string.Empty;
Code above is very simple what it does simple take UserID as an argument and then insert a new record into tbl_invoices table and then after it i am firing a select statement that returns the latest ID into tbl_invoices table. SELECT IDENT_CURRENT(‘table name’) return the id of the last record inserted into the table.
Happy coding bye
Read SMTP settings from asp.net web.config
Jul 16th
hi guyz
Sorry for writing after such a long time i guess i am very busy now a days so for a project i needed to read my smtp email settings defined in my web.config file so after some efforts i am able to read these settings direct from my system .net section.
System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup) config.GetSectionGroup("system.net/mailSettings");
Response.Write("<br>Username="+settings.Smtp.Network.UserName);
Response.Write("<br>Password=" + settings.Smtp.Network.Password);
Response.Write("<br>host=" + settings.Smtp.Network.Host);
Response.Write("<br>port=" + settings.Smtp.Network.Port);
Response.Write("<br>from=" + settings.Smtp.From);
How to get directory name of the page currently displaying
Nov 6th
If you want to know only the directory name not the full path of the page that is currently displaying you can use this code
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Directory.Name.ToString();
Response.Write(“<br><br>Directory name===” + sRet + “<br><br>”);
Happy Coding
Najam Sikander Awan
How to get pagename of itself
Nov 6th
If you want to display the filename or page name of the current displaying page just use these two lines and it will show only the filename like default.aspx, najam.aspx or indexas.aspx no matter it these pages are located deep into your site structure.
string pagename = System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]); Response.Write(pagename);
Enjoy coding
Najam Sikander Awan
The Website Development Process
Apr 14th
I liked this article so copying it from source site and pasting it onto my blog you can also visit source website.

A while ago I put this photo on my flickr page and it was chosen to go on the official flickr blog as the photo of that day (September 23rd). To date it has been viewed over 2000 times.
The photo was actually one in a whole series of photos I shot for a
client presentation, detailing the website design / development process
in a manner that was easily understandable and also fun to look at.
This article takes you through that process, using the same photos. We
hope you enjoy the pictures and if it also helps you to manage your
workflow better if you are starting out as a web designer then that’s
cool too
However, as is the organic nature of these things, there are an
infinite amount of variables that can affect the project timeline. For
that reason, projects are never ever as clear-cut as in this
sequence of photos. Things may need to be done over and over, steps may
get jiggled around, you may need more time for CMS / back-end
development etc – so please think of this sequence as merely a basic example of the kind of process that I have grown comfortable with, speaking as a web designer/developer.

Naturally you’re going to want to start your project with a client
chit-chat. At the first meeting you need to establish the basic scope
of the work – what needs to be done, roles and responsibilities, who is
your point of contact for materials (text content, images) etc.

Think about how you are going to structure things. What is
important? What is not? What needs to be on every page? Depending on
the scale of the project you might want to create a visual sitemap for
your client. Preparing a sitemap is essential if you are reorganising
content in any way.

A wireframe is a skeleton website, indicating all the navigation,
function and content elements that will appear on the final website,
but with no graphic design elements. It is used to iron out
any problems or missing elements, and will act as the blueprint for the
content, design and construction work that comes later.
How you create the wireframe is up to you – for small sites it might
be fine to just line-draw it in Illustrator or Photoshop, but for
larger, more complex sites, it might be necessary to actually code the
wireframe into HTML so the client can click around to check everything
is in the right place.

Working from the sitemap and wireframe, you and the client get
together to start planning the content – specifically the text. Content
planning and writing is probably the biggest workload the client will
have during the project – and it can really take some time.

Whilst all this is going on, the designer can be working on the base design – the homepage and main sub-level pages.

When the base design is ready, the client needs to check that you
are heading in the right direction and suggest adjustments to the
design accordingly.

…which will probably involve going back and tweaking things…

…until everyone is happy.
This process of work-feedback-rework is repeated at
various stages in the project. Besides preparing the content, this
confirmation process is also one of the main responsibilities of the
client.

Once the base design is agreed on, you can start working on the layout and design of each of the individual pages of the site.

And once again they are checked, reworked and then finally confirmed.

You can then begin to build the actual HTML pages…

…and the CSS (I guess I could have put that all in one step, but I really like the little robot guy).

Feedback again. You and the client work together – work-feedback-rework – to polish and tweak things until you have a completed site.

The final stage of production is the debug. The site needs to be
tested across all platforms to iron out any technical problems, and
checked thoroughly for content errors. Naturally, throughout the HTML
& CSS development stage you should be checking cross-browser
functionality anyway but you definitely need a big check at the end too – one that you actually set aside a decent amount of time for.

The picture says “The End” – but of course you don’t just grab the
cheque and run for the door – you need to watch the site for at least
around 10 days or so after launch in case of problems, and if necessary
fix things.
Powered by ScribeFire.