Friday, February 5, 2010

When HttpContext.Current.Request.PhysicalApplicationPath is Null

Well this is gonna be a simple Post ,have you ever tried to Get the Application Physical Path using HttpContext.Current.Request.PhysicalApplicationPath and in return you got a Null Reference Exception? Because HttpContext.Current retruns Null, then System.Web.Hosting.HostingEnvironment.MapPath is where you should go, you give it a virtual Path and it returns the equivalent Physical Path.

Wednesday, November 5, 2008

employees and business meetings


Managers sometimes follow weird strategies to make employees attend business meeting. I have heard about some of these weird strategies and I was totally shocked. Business meetings will be effective, valuable and useful only if there is a common language between both manager and employees.

There are a lot of questions need to be answered by you as a manager

Why do employees hate business meeting?

What can be done to make them attend business meetings not just because they have to but also because they love to?

How can I as a manager benefit from Business meeting?

Should employees also benefit from Business meeting?

According to my point of view employees hate business meeting because it is boring, the feeling that they are there just to listen .no argues, no contributions also make them hate to attend. If you let employees feel that there is only one decision maker in the organization this may lead to more dangerous things than just hate to attend Business meetings.

In Business meetings everyone is there to benefit from others, Managers are there to benefit from employees and employees are there to benefit from each other and from Managers.

Listen to your employee’s point of views about your decisions and ask for suggestions.

Here are small tips that can be done:

1- Make a title for each meeting, this title should be a challenging one, and ask your employees to help you choosing the title of the next meeting.


2- There should be an Agenda highlighting the main issues you are going to discuss, this Agenda should be with employees at least a day before the meeting.


3- Reserve the first 15 minutes of each meeting , asking if the last meeting was effective, if the things that you all agreed to be done are already handled or what?.


4- Make a monthly award for the best contributors in meetings.


5- Choose one of the most effective employees and let his/her name be the title of one of the meetings.


6- Never feel shame to ask your employees if you have met their expectations.


7- Try to introduce the problems (if any) to your employees not to introduce your employees to problems.


8- Get your employees involved in the meeting, talk, argue and finally come to a conclusion.


9- Let your employees feel that they are decision makers.


10- Employees are not there just to listen to you; you should listen to them more.


11- Ask employees how they see the Organization after 5 years and from their answers you can see how good and bad is the organization.


12- Forget about this sulky manager; try to impress your employees with your smile.



13- Let your employees see that you are seeking solutions rather than seeking punishment as a solution , punishment is not a modern solution and it affect employees badly.

and finally act as if the organization is there not to take from employees but to give them and they will give the organization more that what you expect.


Sunday, October 19, 2008

What Makes a Good Business Analyst By Tony de Bree


There are several key points one needs to understand before deciding whether or not to become a business analyst. You may be qualified to do the job you were hired to do. Yet is it the job you wanted to do? Some analysts find themselves locked in a cubical writing reports all day, only to find the report was not used or even read. They realize they are in a dead end job going no-where fast. This is not the usual dream one has when becoming a business analyst.

A good business analyst is creative, a people person. Someone wanting a more hands on approach to business and problem solving. The good business analyst will look for opportunities to grow and learn. He or she will listen attentively to what others are saying. The good business analyst is like a walking encyclopedia about the company he or she works within. They will know people from every department.

The good business analyst may be a part of the IT team or department. He or she may even be able to produce usable code for practical remedies to small tasks. He or she will understand technology and the jargon that leaves the common layperson confused.

What makes a good business analyst is the ability to listen to what is being said and hear what is not. The good business analyst can read into the meaning of stakeholders words. He or she can understand the needs being expressed when the stakeholders do not always know what they are. The good business analyst will be able to determine if the requests from stakeholders or end users are viable. In some cases they are not and it is up to the business analyst to inform what can be done versus what is wanted.

The good business analyst will have information available about the latest technology. He or she will know the formulas or programs used by corporate peers. The good business analyst will be able to recognize trends and differentiate between them and fads. They will understand the end user market.

The good business analyst will understand people. He or she will be a motivational person who can gear people into wanting to complete a project. The good business analyst will be able to point out someone's strengths and help to build on those. He or she will recognize when a person is having a conflict and try to help resolve the issue. He or she may even be able to create teamwork within separate departments to meet a goal or deadline.

The good business analyst commands respect because he or she gives respect. You will not find the good business analyst spreading rumors or gossiping. He or she will squelch the first signs of trouble and stand up for what he or she believes in. There is no room for garbage in the office.

The good business analyst is a visionary, a creative thinker, and innovative. He or she is fun to work with and carries a positive attitude. Very few people do not like the good business analyst.

the Original Link

Thursday, September 11, 2008

Repeater with Empty Data Template



most of us are using Repeaters to display Data also we faced the situation of retrieving no result to display so the Repeater will be Empty or we will need to handle this case from code behind to check the number of items and if zero we show a label with No Result found or no records to display message.

we can do this with a simpler way and with no need to write anything in code behind ,let's see how


<asp:Repeater ID="RptrContacts" runat="server">

<ItemTemplate>

<!-- Add your Item Template Here -->

</ItemTemplate>

<FooterTemplate>

<asp:Label ID="lblEmpty"

Text="no result" runat="server"

Visible='<%#bool.Parse((RptrContacts.Items.Count==0).ToString())%>'>

</asp:Label>

</FooterTemplate>

</asp:Repeater>



here we will display a label with "no result" message in the footer we just need to add a label and set it's text property with the message we want.

then we set the Visible property of the label with the value coming out from the following expression


<%#bool.Parse((RptrContacts.Items.Count==0).ToString())%>


it checks if the number of Items equals zero or not , if it equals zero it returns True so the label will be visible and if not it will return False so the label will be invisible.

Saturday, August 16, 2008

Custom Controls in Details(Part 1)

Most of us are using User Controls that enable us to create a Control that can be used many times in the same project and sure this helps us not to duplicate the code but what if you want this user Control to be used in different projects in this Case you can not use User Controls as you will have to Create this User Control in every new project you may need to use this User Control in, in this Case you may need to Use Custom Controls instead of User Controls.

Limitations of User Controls:

-Can not be shared among Different Projects.
-Can not inherit from other Server Side Controls.

Custom Controls Adv:

-Can be shared among Different Projects.
-Can inherit from other Server Side Controls.
-A Custom Control can inherit from another Custom Control.

Custom Controls DisAdv:

-you can not say that its complex but it may require much work than User Controls.

Let's see if Custom Controls are Complex or not 

Example (1)
In this example we will try to create a TextBox with a label, most of the times we are using TextBoxs we need to put a label before this TextBox to define the type of Data to be written in it, don’t you think that it will be good if you have both of them in a one Server Control, let's start

Step (1)


Open your Visual Studio

VS 2005 File-->New -->Project-->Visual C#-->Windows -->WebControlLibrary


VS 2008 File-->New -->Project-->Visual C#-->Web -->ASP.Net Server Control


Step (2)
Now you need to create a website to be able to test your site so add a new website to this Project

Step (3)

Let's go back to our server Control and start to code

First of all we want to add a label and Textbox we can do that by overriding the CreateChildControls method, Controls are added to your Custom Control in this Method so let's add the Label and the TextBox

First let your Class inherits from System.Web.UI.WebControls.WebControl

Then override CreateChildControls method

protected override void CreateChildControls()
{
this.ChildControlsCreated = true;
this.Controls.Clear();

Label lblID = new Label();
lblID.Text =LabelText ;
lblID.ID = LabelID;

TextBox txt = new TextBox();
txt.ID = TextBoxID;


this.Controls.Add(lblID);
this.Controls.Add(txt);
}

First we set the Property ChildControlsCreated to true to be as an indicator that our Controls are created we will speak about this later then we Clear all the previously added Controls, declare our Label and TextBox then add them to the Custom Control Controls.

Step (4)
Now build this project, and then go back to your test website and open the test page design and you will find your control added to the Toolbox, Drag and Drop it to your page you will see nothing as the CreateChildControls method adds your controls at runtime but still you can view your controls just follow the following step.



Step (5)
Let's override onInit method to be able to see your Controls at design time

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (this.DesignMode == true)
{
this.EnsureChildControls();
}
}

First we check that if you are displaying this Custom Control in design mode then call the EnsureChildControls Method which first Check the value of the Property ChildControlsCreated that we mentioned before this Property is just to make sure that our Controls will not be created more than once. If the value is true then it will not create the Controls if false it will create our Controls.

Now build your Server Control project again, and go back to your page and refresh it and you will see your controls.



Step (6)
Now we need to make sure that the name of our server Control will be unique we can make ASP.Net to prefix our controls (Label and Textbox) with the name of the Custom Control, just let your Server Control implement INamingContainer Interface



Step (7)
Now you want to be able to access the Label and the TextBox from the Controls collection in your Custom Control using FindControl Method, you can do this by assigning a value to the ID property of both the Label and TextBox.

Let's see how we can do so, now switch to your Code Behind

And add two properties one for Label ID and TextBox ID

[Bindable(true)]
[Category("Misc")]
[DefaultValue("")]
[Localizable(true)]
public string TextBoxID
{
get
{
String s = (String)ViewState["TextBoxID"];
return ((s == null) ? "[" + this.ID + "]" : s);
}

set
{
ViewState["TextBoxID"] = value;
}
}

And one for Label ID

[Bindable(true)]
[Category("Misc")]
[DefaultValue("")]
[Localizable(true)]
public string LabelID
{
get
{
String s = (String)ViewState["LabelID"];
return ((s == null) ? "[" + this.ID + "]" : s);
}

set
{
ViewState["LabelID"] = value;
}
}

Now build your server control project and back to your test page and refresh it, select your server control and press F4 and see the properties



Step (8)
Now you want to set the Text Property of your Label just add the following property


[Bindable(true)]
[Category("Appearance")]
[DefaultValue("Label")]
[Localizable(true)]
public string LabelText
{
get
{
String s = (String)ViewState["LabelText"];
return ((s == null) ? "[" + this.ID + "]" : s);
}

set
{
ViewState["LabelText"] = value;
}
}


now run your Server Control Project and go back to your test Page ,refresh it
then view the properties of your Custom Control and you will find your property there


Step (9)
Now you want to know more about Style and how to apply style to your Custom Control,let's try to add a style to our Custom Control

body {
}
.textbox
{
background-color:Red;
}


now in the CssClass Property of your Server Control write textbox, and run your page


may be you need to apply a style to label only on TextBox only or even Different Style for both, let's see how we can do this

let's first create our style classes

.textboxbackground
{
background-color:Red;
}

.labelbackground
{
background-color:Blue;
}


then back to your server control Code Behind and add the following Properties


[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string LabelCssClass
{
get
{
String s = (String)ViewState["LabelCssClass"];
return ((s == null) ? "[" + this.ID + "]" : s);
}

set
{
ViewState["LabelCssClass"] = value;
}
}


[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string TextBoxCssClass
{
get
{
String s = (String)ViewState["TextBoxCssClass"];
return ((s == null) ? "[" + this.ID + "]" : s);
}

set
{
ViewState["TextBoxCssClass"] = value;
}
}



and in CreateChildControls Method add the following lines

lblID.CssClass = LabelCssClass;
txt.CssClass = TextBoxCssClass;


now build your Server Control Project and switch back to your test page and as usual refresh it and view the Properties of your Control and fill it with Style Classes names


now run your test page

Thursday, August 14, 2008

Use extension Methods to Add new Functionality to ASP.Net Server Controls

i'm sure that most of you know enough about extension methods and for those who don't ,
extension methods are used to new methods to an existing type without any effort to modify the original type.

let's now start to see how we can use extension methods to add new functionality to ASP.Net Server Control.

example (1)

-with DropDownList

here is the original way of adding new Items to DropDownList


DropDownList1.Items.Add(new ListItem("mona"));

or

ListItem li = new ListItem("mona");
DropDownList1.Items.Add(li);


actually if you are going to Add only one item it's ok but what if you are going to add an array of items sure you are going to repeat the previous lines of code many times, let's now try to use an extension method to help us

step(1)
Create a static Class called ControlsUtil

public static class ControlsUtil
{

public static void AddToDDList(this DropDownList ddl, string values, bool IncludeEmpty)
{
string [] splitter;
if (IncludeEmpty)
splitter = values.Split(new char[] { ',' }, StringSplitOptions.None);
else
splitter = values.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
int Count = 0;
while (Count <>


step(2)

Create a web Page and add a DropDownList

step(3)
Switch to Code Behind and write the following Code

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.AddToDDList(" ,A,B,C,D,E,F,G,H", true);
}
}


step(4)
run you page and see the result






- with WebPage

in many web pages there might be a lot of Textboxs that you may need to clear after clicking certain button sure you can Create your own method that clear all the Textboxs but you still need to repeat this method in every page, now let's use extension methods to help us.

step (1)

Open the Static class that we created before and add the following method


public static void ClearTextBoxs(this object obj,IEnumerable e)
{
foreach (object o in e)
{
TextBox txt = o as TextBox;
if (txt != null)
txt.Text = string.Empty;
}
}


step (2)

Create your web page that contains any number of Textboxs and a button



step (3)

now switch to code behind of the Button Click event and add the following code

protected void Button1_Click(object sender, EventArgs e)
{
this.ClearTextBoxs(form1.Controls);
}


step (4)

run your page ,add text to the TextBoxs



step (5)

then Click the Button and see the result


Note: this method can also be used with UserContols not just webPages

How to execute both Client side code and Server side code

sometimes you may need to call a Client Side code with Server Side Code, let's assume that you have a Button and you want to call a certain javascript function beside your function in the Code Behind,
here are some of the Examples when you may need so:

1-Prevent User from Pressing certain Button more than once ,i.e Disable this Button until the server Side Function is processed



here you have both onclick and onclientclick functions also i use usesubmitbehavior this property indicates whether your Button will use the Client Browser's Submit or will use the Postback which means that the page will be posted to the Server, here we set it to false which means that it will do Postback.

2-Display a messagebox after Clicking the Button




hope you enjoy it.