Wednesday, May 20, 2009
multiple submit buttons and the enter key
The defaultButton property of Panel or Form is used to ensure Enter Key Submission. Typically people used to Enter Key submission and if it is disabled, it might be annoying certain times.
The defaultButton really provides a way to handle Enter Keys for respective portions of the page when the focus is there.
Example:
<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>
<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>
Friday, April 24, 2009
Extract links from html in C#
{
List
string startSquence = "<a";
string endSequence = "</a>";
html = html.ToLower();
while (html.IndexOf("<a") != -1)
{
int start = html.IndexOf(startSquence) ;
int end = html.IndexOf(endSequence, start+startSquence.Length);
//Extract the link, and add it to the list
if (end > start)
{
string link = html.Substring(start, end + endSequence.Length - start);
//Check b
if (link.Substring(1).IndexOf(startSquence) != -1)
{
html = html.Substring(start + startSquence.Length);
continue;
}
if (link != string.Empty)
{
links.Add(link);
}
}
else if (end < start)
{
html = html.Substring(start + startSquence.Length);
continue;
}
//Trim the raw data
html = html.Substring(end + endSequence.Length);
}
return links;
}
Wednesday, April 22, 2009
how to modify web.config in asp.net using C#
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings.Add("CommentsLimit", "10");
myConfiguration.Save();
To update the existing property:
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings["CommentsLimit"].Value = "20";
myConfiguration.Save();
Thursday, April 9, 2009
virtual keyword in C#
The class member method may be overriden even if the virtual keyword is not used, but its usage makes the code more transparent & meaningful.
When the override keyword is used to override the virtual method, in a scenario where the base class method is required in a child class along with the overriden method, then the base keyword may be used to access the parent class member. The following example will be helpful to understand.
public class Shape
{
string name;
public virtual void SetName(string name)
{ this.name = name; }
}
public class Circle : Shape
{
//This method is being overriden
public override void SetName(string name)
{
base.SetName("circle"); //We are calling parent class method
}
}
Wednesday, April 8, 2009
How to Backup MySQL Database automatically in linux
15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data '+%m-%d-%Y'`.sql.gz
The first part is "15 2 * * *". The five fields mean "minute, hour, day of month, month, day of week" respectively. The character '*' stands for "any".
The next, "root", means "run following command as root account".
You can use cron job so that it takes backup daily.
Friday, March 20, 2009
World Sleep Day 2009
World Sleep Day is an international annual event, intended to be a celebration of sleep and a call to action on important issues related to sleep, including medicine, education, social aspects and driving. It aims to lessen the burden of sleep problems on society through better prevention and management of sleep disorders. World Sleep Day 2009 is being held on March 20th, under the slogan ‘Drive alert, arrive safe’. This year’s theme is transportation, focussing on safety, travel and driving alertness.
The first World Sleep Day was launched on March 14th 2008. Events involving local groups took place in public settings around the world and online with the unveiling of a declaration, presentation of educational materials, and exhibition of videos.
The World Sleep Day declaration is as follows:
| |
The World Sleep Day Committee would like you to assist in raising awareness of World Sleep Day 2009 by carrying out related activities in your country. World Sleep Day Committee members:
Antonio Culebras, co-chair
Liborio Parrino, co-chair
Richard Allen,
Sudhansu Chokroverty,
Christian Guilleminault,
Mario Terzano,
Robert Thomas,
Claudia Trenkwalder,
Allan O’Bryan, WASM Executive Director.
Source:http://worldsleepday.wasmonline.org/
Thursday, March 5, 2009
How to validate integer in c#
try
{
int t = Convert.ToInt32("wrongval");
}
catch
{
}
while the best approach to test must be:
int num = 0;
Int32.TryParse("wrongval", out num); //It will not throw any exception, In case of failure, it set the value of num to zero and also return FALSE.
if you see the performance of above two methods, you will be amazed that the TryParse method is 1000 times faster than Convert.ToInt32.