Pages

Friday, June 26, 2009

ASP.NET Coding Standards and Guidelines

ASP.NET Coding Standards and Guidelines


1. Prefix user control names with “uc”

2. The rest of the user control name should be in Pascal Casing (Ex. ucMyUserControl)

3. Do not use session variables throughout the code. Use session variables only within the classes and expose methods to access the value stored in the session variables.

4. Do not store large objects in session, it may consume lot of server memory depending on the number of users.

5. Always use style sheet to control the look and feel of the pages.

6. Categories data and store it in predefine folder depending on its working.(e.g.- store all images, sound, video files in media or image folder)

Control NameAbbreviations/ PrefixesRemarks
Formwf,frm
TextboxTxt
TextAreaTxa
CheckboxChk
Check Box ListChklstchklstCurrency
LabelLbl
Hidden ElementsHdn
Combo Box / Drop DownCbo
Buttoncmd,btn
Submit Buttonsmt
Reset Buttonrst
Link ButtonlbtnlbtnSave
Image ButtonibtnibtnExit
Password Fieldpwd
Radio Buttonopt
Radio Button ListoptlstoptlstSelect
List Boxlst
Framefra
Imageimg
Pointerptr
Panelpan,pnlpnlBackground
Place Holderplh
Calendarcal
Ad Rotatoradr
TabletbltblAppointments
Range Validatorrav,rgv
Regular Expression Validatorrev
Regular Field Validatorrfv
Compare Validatorcmv
Custom Validatorcuv,csv
Validation Summaryvsm
XMLXmlXmlDataFile
File FieldFle
LiteralLit
ArraylistAl
Hyperlinkhyp
DataGriddtg,dgr
DataListdtl
RepeaterrptrptReport
Flow Layout Panelflp
Grid Layout Panelglp
Horizontal Rulehr
Crystal Report Viewercrv,crvrcrvReport


Main Article

Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Thursday, June 25, 2009

Creating Context Menu for Data Grid.

We can create context menu for the Data Grid cell here is the code to create the context menu and to assign the event..


// creating Context menu for data grid.
ToolStripMenuItem mnuStart = new ToolStripMenuItem("Start");
ToolStripMenuItem mnuStartAll = new ToolStripMenuItem("StartAll");
ToolStripMenuItem mnuPause = new ToolStripMenuItem("Pause");
ToolStripMenuItem mnuDelete = new ToolStripMenuItem("Delete");

mnuStart.Click += new EventHandler(mnuStart_Click); // creating the event handeler for the context menu.
mnuStartAll.Click += new EventHandler(mnuStartAll_Click);
mnuPause.Click += new EventHandler(mnuPause_Click);
mnuDelete.Click += new EventHandler(mnuDelete_Click);

//Add to main context menu
mnu.Items.AddRange(new ToolStripItem[] { mnuStart, mnuStartAll, mnuStartAll, mnuPause, mnuDelete });


and for assigning it for the Mouse Right Click please use the following code..



private void dgFile_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (dgFile.Rows.Count == 0)
{
dgFile.ContextMenuStrip = null;
}
else
{
dgFile.ContextMenuStrip = mnu;
}
}
}
Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Wednesday, June 24, 2009

Santa & Banta Back again.....

Boss: Where were you born?
Sardar: India ..
Boss: which part?
Sardar: What 'which part'? Whole body was born in India .

2 sardar were fixing a bomb in a car.
Sardar 1: What would you do if the bomb
explodes while fixing.
Sardar 2: Dont worry, I have one more.


Sardar: What is the name of your car?
Lady: I forgot the name, but is starts with 'T'.
Sardar: Oh, what a strange car, starts with Tea. All cars that I know start with petrol.

Sardar joined new job. 1st day he worked till late evening on the computer. Boss was happy and asked what you did till evening.
Sardar: Keyboard alphabets were not in order, so I made it alright.

Museum Administrator: That's a 500-year-old statue u've broken..
Sardar: Thanks God! I thought it was a new one.


At the scene of an accident a man was crying: O God! I have lost my hand, oh!
Sardar: Control yourself. Don't cry. See that man. He has lost his head. Is he crying?

Sardar: U cheated me.
Shopkeeper: No, I sold a good radio to u.
Sardar: Radio label shows Made in Japan but radio says this is 'All India Radio! '

NOW THE LAST TWO ULTIMATE:
In an interview, Interviewer: How does an electric motor run?
Sardar: Dhhuuuurrrrrrrrrr. .....
Inteviewer shouts: Stop it.
Sardar: Dhhuurrrr dhup dhup dhup....

Tourist: Whose skeleton is that?
Sardar: An old king's skeleton.
Tourist: Who's that smaller skeleton next to it?
Sardar: That was same king's skeleton when he was a child.


Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Tuesday, June 23, 2009

Reading a XML file..

hi all,

Here is the code for reading all node or selected node of a XML file. We just have to take a xmlTextReader object and using that we can read the content of the xml file.



XmlTextReader xRead = new XmlTextReader((Application.StartupPath + "\\" + strNewFile));
try
{
//Reading the XML file
while (xRead.Read())
{
XmlNodeType nodeType = xRead.NodeType;

if (nodeType == XmlNodeType.Element)
{
if ((xRead.Name == "graphic") || (xRead.Name == "inline-graphic"))
{
if (xRead.HasAttributes)
{
xRead.MoveToAttribute(0);
strImagename = xRead.Value;
}
}
}
}
}

Thanks
Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Monday, June 22, 2009

Creating controls at runtime in a web form

Hi,
Many time the need arises to create the controls in the web form while running the application. Here is the sample code to do the above task, even we can also create the event associated with that controls. In the Page load of the form where we want to create the control, write the following lines of code. For example i am creating a LINK BUTTON.

protected void Page_Load(object sender, EventArgs e)
{
LinkButton lnk = new LinkButton();
lnk.ID = "lnk" + 1;
lnk.Text = "more1";
lnk.Click += new EventHandler(LinkButton3_Click);
form1.Controls.Add(lnk);
}

protected void LinkButton3_Click(object sender, EventArgs e)
{
Response.Write("Hello! Runtime created control");
}

you can create the other controls also using the above methods.. Thanks


Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Tuesday, June 9, 2009

Writing Excel file with data set

here is the way by which we can create a excel file. here i hvae use a data set in which all the values are present which i want to write in the excel sheet.

first of all the column head is stored in an array and the value is present in the data set.  You just need to add the COM reference in the application using the Microsoft 12.0 Excel object library.
Use the name space to create the excel object.
                                           

string[] sExcelRow ={ "A", "B", "C", "D", "E", "F", "G", "H", "I",}
 Microsoft.Office.Interop.Excel.Sheets sheets;                 

                  Microsoft.Office.Interop.Excel.Workbooks workbooks = exc.Workbooks;

                  Microsoft.Office.Interop.Excel._Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);

                  sheets = workbook.Worksheets;

                  Microsoft.Office.Interop.Excel._Worksheet worksheet;
                  worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);


   for (int i = 0; i <>
                  {
                      worksheet.get_Range(sExcelRow[i] + 1,  sExcelRow[i] + 1).Value2 = sExcelCol[i].ToString();
                      worksheet.get_Range(sExcelRow[i] + 1, sExcelRow[i] + 1).Font.Bold = true;
                      worksheet.get_Range(sExcelRow[i] + 1, sExcelRow[i] + 1).HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;
                      worksheet.get_Range(sExcelRow[i] + 1, sExcelRow[i] + 1).EntireColumn.AutoFit();



  for (int j = 0; j <>
                  {
                      string strFieldStatus = string.Empty;
                      for (int l = 0; l <>
                      {
                      
                              worksheet.get_Range(sExcelRow[l] + x, sExcelRow[l] + x).Value2 = System.IO.Path.GetFileName(Convert.ToString(ldsUser1.Tables[0].Rows[j][l + 1]));
                              worksheet.get_Range(sExcelRow[l] + x, sExcelRow[l] + x).EntireColumn.AutoFit();
                              worksheet.get_Range(sExcelRow[l] + x, sExcelRow[l] + x).EntireColumn.NumberFormat = "@";

                        }


workbook.SaveAs(strFile1, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, false, false, Type.Missing, Type.Missing, Type.Missing);
 workbook.Close(true, Type.Missing, Type.Missing);



Anil Kumar Pandey
System Architect
Green Point Technology (India) Ltd.
Mumbai, Maharshtra
INDIA

Kontera