Sunday, September 28, 2008

Multiline in tootip

you the below codes to add multiline tooltip for a button :

btnConvert.ToolTip = String.Format("This{0}is{0}a{0}multiline{0}tooltip", Environment.NewLine);

btnConvert.ToolTip = String.Format("YTD Excellence {0}\nYTD Overall {1}\nFeb Excellence {2}\nFeb Overall {3}",
"1",
"2",
"3",
"4"
);

Wednesday, August 27, 2008

Programmatically Creating Server Controls

// Create a new HtmlTable object.
HtmlTable table1 = new HtmlTable();
// Set the table's formatting-related properties.
table1.Border = 1;
table1.CellPadding = 3;
table1.CellSpacing = 3;
table1.BorderColor = "red";
// Start adding content to the table.
HtmlTableRow row;
HtmlTableCell cell;
for (int i = 1; i <= 5; i++)
{
// Create a new row and set its background color.
row = new HtmlTableRow();
row.BgColor = (i % 2 == 0 ? "lightyellow" : "lightcyan");
for (int j = 1; j <= 4; j++)
{
// Create a cell and set its text.
cell = new HtmlTableCell();
cell.InnerHtml = "Row: " + i.ToString() +
"
Cell: " + j.ToString();
// Add the cell to the current row.
row.Cells.Add(cell);
}
// Add the row to the table.
table1.Rows.Add(row);
}
// Add the table to the page.
this.Controls.Add(table1);

Monday, May 26, 2008

Send Mail

MailMessage msgMail = new MailMessage();
SmtpMail.SmtpServer = "192.xxx.xxx.xxx";
msgMail.To = y@p.com;
msgMail.Cc = s@p.com,j@p.com;
msgMail.Bcc = b@p.com;
msgMail.From = H@p.com;

msgMail.Subject = "ارسال توضيحات توسط پرسنل شماره " + lblPNo.Text;
//User.Identity.Name.Substring(15, User.Identity.Name.Length - 15);
msgMail.BodyFormat = System.Web.Mail.MailFormat.Html;
msgMail.BodyEncoding = System.Text.Encoding.UTF8;
string strBody =
"" +
" رزرو سالن جلسه " +
" " +
" " +
" " +
"
بسمه تعالي
به: اموراداري
به اطلاع مي رساند كارمند با شماره پرسنلي " +
"" + lblPNo.Text +
"
" + " توضيحاتي را براي شما ارسال نموده است. " +
"
" +
"
" +
"لطفا بررسي فرمائيد.
با تشكر " +
"
سيستم منابع انساني
";
msgMail.Body = strBody;
System.Web.Mail.SmtpMail.Send(msgMail);

Network User

You can find network user by this code:

User.Identity.Name.Substring(15, User.Identity.Name.Length - 15);

Tuesday, May 13, 2008

Solving out ASP.NET Enter key problem

Introduction
When I start programming with ASP.NET I used to face problems with enter key. Clicking enter key won't make a button click at all times. It will post back the form, but the relevant button you wanted to call won't be called. I read several articles which discuss this problem and tried some of the methods suggested by them. But nothing gave me a stable performance. So I created a library that can set default button for text box control when the enter key is pressed.

Identifying problem
Hitting enter key on ASP.NET pages will produce really different results. It varies on each browser. You can test it by placing one text box and one button on a webform. Write some code in button's onclick event. It could be some thing like

Response.write("You clicked this button");

Try debugging the program. Pressing enter key on the text box will make a postback. But whatever code you written inside button click won't be executed. This will work some time in firefox.

Then I found some ASP.NET developers was saying, "you can achieve this by putting one hidden field". So I placed something like this.



Start debugging again. Now pressing enter key will post form and execute the code for the button's onclick. Looks strange !

But that worked as temporary solution. This method can't be implemented when there is more than one button.

Assume you have two text boxes and two buttons. Hitting enter key from first text box should call first button and second text box should call second button. In this case hidden textbox method fails. It will call one button every time.

To solve this and make it work with all situations we can use javascript.

Using javascript for solution
txtBox1.Attributes.Add("onkeydown", "if(event.which event.keyCode){if ((event.which == 13) (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; ");

Adding the above attribute to the textbox will solve the problem. The keycode for enter key is 13. When a key is pressed in textbox it will check the keycode is 13. If it is 13 the relevant button will be clicked. event.keycode will not work with firefox, so we are using event.which.

Porting into DefaultButton class
I ported the same code into a class. Using this you can pass the textbox object and button object. It will set the necessary scripts for making enter key working. There are two static methods in DefaultButton class. One is for normal asp.net button and next is for image button.

To set default button for one text box follow these steps

Add reference to the library
Import System.Web.UI.DefaultButton namespace
Use DefaultButton.SetDefaultButton ( control , btButton )
This method will add keydown attribute for the textbox control and calls button when enter key is pressed.

Setting default buttons in ASP,NET 2.0
ASP.NET 2.0 comes with defaultbutton property. You can set default button for form and panels. This will be called when form is posting back using enter key.


source:http://www.codeproject.com/KB/aspnet/aspnet_Enter_key_problem.aspx









License

Sunday, May 11, 2008

Digit to String

This is procedure to convert no to string:


public static String ConvertDigitToString(string No, string Currency)
{
return ConvertDigitToString(Convert.ToInt64(No), Currency);
}
public static String ConvertDigitToString(Int64 No, string Currency)
{
string adad = "", bilion, miliard, million, thousand, digit, EnteredNo = No.ToString();
for (; EnteredNo.Length < 15; EnteredNo = "0" + EnteredNo) ;
bilion = EnteredNo.Substring(0, 3);
miliard = EnteredNo.Substring(3, 3);
million = EnteredNo.Substring(6, 3);
thousand = EnteredNo.Substring(9, 3);
digit = EnteredNo.Substring(12, 3);
if (bilion != "000")
{
adad = ReadDigit(bilion);
adad = adad + " ïéïيë ";
}
if (miliard != "000")
{
if (adad != "") adad = adad + "ي ";
adad = adad + ReadDigit(miliard);
adad = adad + " êïéïں©§ ";
}
if (million != "000")
{
if (adad != "") adad = adad + "ي ";
adad = adad + ReadDigit(million);
adad = adad + " êïéïيë ";
}
if (thousand != "000")
{
if (adad != "") adad = adad + "ي ";
adad = adad + ReadDigit(thousand);
adad = adad + " ىھں© ";
}
if (digit != "000")
{
if (adad != "") adad = adad + "ي ";
adad = adad + ReadDigit(digit);
}
return adad + " " + Currency;
}
private static String ReadDigit(string EnteredDigits)
{
string Sadgan, Dahgan, Yekan, adad = "";
Sadgan = EnteredDigits.Substring(0, 1);
Dahgan = EnteredDigits.Substring(1, 1);
Yekan = EnteredDigits.Substring(2, 1);
if (Convert.ToInt16(Sadgan) != 0)
{
switch (Convert.ToInt16(Sadgan))
{
case 1: adad = "ïè­§"; break;
case 2: adad = "§يï«¢"; break;
case 3: adad = "«ï­§"; break;
case 4: adad = "چىں© ­§"; break;
case 5: adad = "پںë­§"; break;
case 6: adad = "¬¬­§"; break;
case 7: adad = "ىه¢­§"; break;
case 8: adad = "ى¬¢­§"; break;
case 9: adad = "ëى­§"; break;
}
if (((Convert.ToInt16(Dahgan) != 0) (Convert.ToInt16(Yekan) != 0)) &&
(Convert.ToInt16(Sadgan) != 0)) adad = adad + " ي ";
switch (Convert.ToInt16(Dahgan))
{
case 1:
switch (Convert.ToInt16(Yekan))
{
case 0: adad = adad + "§ى"; break;
case 1: adad = adad + "ïںھ§ى"; break;
case 2: adad = adad + "§يںھ§ى"; break;
case 3: adad = adad + "«ïھ§ى"; break;
case 4: adad = adad + "چىں©§ى"; break;
case 5: adad = adad + "پںëھ§ى"; break;
case 6: adad = adad + "¬ںëھ§ى"; break;
case 7: adad = adad + "ىه§ى"; break;
case 8: adad = adad + "ى¤§ى"; break;
case 9: adad = adad + "ëيھ§ى"; break;
}
break;
case 2: adad = adad + " ï«¢"; break;
case 3: adad = adad + "«ï"; break;
case 4: adad = adad + "چىé"; break;
case 5: adad = adad + "پë¤ںى"; break;
case 6: adad = adad + "¬­¢"; break;
case 7: adad = adad + "ىه¢ں§"; break;
case 8: adad = adad + "ى¬¢ں§"; break;
case 9: adad = adad + "ëي§"; break;
}
if ((Convert.ToInt16(Yekan) != 0) &&
(Convert.ToInt16(Dahgan) != 0) &&
(Convert.ToInt16(Dahgan) != 1)
) adad = adad + " ي ";
switch (Convert.ToInt16(Yekan))
{
case 1: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ïè"; break;
case 2: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "§ي"; break;
case 3: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "«ى"; break;
case 4: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "چىں©"; break;
case 5: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "پë¤"; break;
case 6: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "¬¬"; break;
case 7: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ىه¢"; break;
case 8: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ى¬¢"; break;
case 9: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ëى"; break;
}
}
else
if (Convert.ToInt16(Dahgan) != 0)
{
switch (Convert.ToInt16(Dahgan))
{
case 1:
switch (Convert.ToInt16(Yekan))
{
case 0: adad = adad + "§ى"; break;
case 1: adad = adad + "ïںھ§ى"; break;
case 2: adad = adad + "§يںھ§ى"; break;
case 3: adad = adad + "«ïھ§ى"; break;
case 4: adad = adad + "چىں©§ى"; break;
case 5: adad = adad + "پںëھ§ى"; break;
case 6: adad = adad + "¬ںëھ§ى"; break;
case 7: adad = adad + "ىه§ى"; break;
case 8: adad = adad + "ى蠟ى"; break;
case 9: adad = adad + "ëيھ§ى"; break;
}
break;
case 2: adad = adad + " ï«¢"; break;
case 3: adad = adad + "«ï"; break;
case 4: adad = adad + "چىé"; break;
case 5: adad = adad + "پë¤ںى"; break;
case 6: adad = adad + "¬­¢"; break;
case 7: adad = adad + "ىه¢ں§"; break;
case 8: adad = adad + "ى¬¢ں§"; break;
case 9: adad = adad + "ëي§"; break;
}
if ((Convert.ToInt16(Yekan) != 0) && (Convert.ToInt16(Dahgan) != 1)) adad = adad + " ي ";
switch (Convert.ToInt16(Yekan))
{
case 1: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ïè"; break;
case 2: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "§ي"; break;
case 3: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "«ى"; break;
case 4: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "چىں©"; break;
case 5: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "پë¤"; break;
case 6: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "¬¬"; break;
case 7: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ىه¢"; break;
case 8: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ى¬¢"; break;
case 9: if (Convert.ToInt16(Dahgan) != 1) adad = adad + "ëى"; break;
}
}
else
{//Convert.ToInt16(Dahgan)=0
switch (Convert.ToInt16(Yekan))
{
case 1: adad = adad + "ïè"; break;
case 2: adad = adad + "§ي"; break;
case 3: adad = adad + "«ى"; break;
case 4: adad = adad + "چىں©"; break;
case 5: adad = adad + "پë¤"; break;
case 6: adad = adad + "¬¬"; break;
case 7: adad = adad + "ىه¢"; break;
case 8: adad = adad + "ى¬¢"; break;
case 9: adad = adad + "ëى"; break;
}
}
return adad;
}

Sunday, May 4, 2008

Java script functions

You can find some javascript Math in this address:

Java Script