You can add as many attributes you want in any control the limitation is that it must know those attributes.
_textarea = new HtmlTextArea();
_textarea.ID = "HAHA";
_textarea.Attributes.Add("onkeypress","return taLimit()");
_textarea.Attributes.Add("onkeyup","return taCount(myCounter)");
_textarea.Attributes.Add("name","Description");
_textarea.Attributes.Add("rows","7");
_textarea.Attributes.Add("wrap","physical");
_textarea.Attributes.Add("runat","server");
_textarea.Cols = 40;
_textarea.Attributes.Add("maxLength","255");
In the above code you can see that I added many attributes to the HtmlTextArea control.
Thursday, December 30, 2004
Thursday, December 23, 2004
Sorting in ArrayList (Ascending and Descending Order)
Here you how you can sort the ArrayList in Ascending and Descending Order.
Ascending Order:
for(int i=0;i<=_leftListBox.Items.Count-1;i++)
{
aList.Add(_leftListBox.Items[i].Text);
}
aList.Add("Azam");
aList.Add("aa");
aList.Add("haha");
aList.Sort();
Descending Order:
for(int i=0;i<=_leftListBox.Items.Count-1;i++)
{
aList.Add(_leftListBox.Items[i].Text);
}
aList.Add("Azam");
aList.Add("aa");
aList.Add("haha");
aList.Sort();
aList.Reverse(); // This sorts it in Descending order
if you use something like this it wont work and than you have to implement the IComparable interface:
foreach(ListItem item in _leftListBox.Items)
{
aList.Add(item);
}
aList.Sort();
Ascending Order:
for(int i=0;i<=_leftListBox.Items.Count-1;i++)
{
aList.Add(_leftListBox.Items[i].Text);
}
aList.Add("Azam");
aList.Add("aa");
aList.Add("haha");
aList.Sort();
Descending Order:
for(int i=0;i<=_leftListBox.Items.Count-1;i++)
{
aList.Add(_leftListBox.Items[i].Text);
}
aList.Add("Azam");
aList.Add("aa");
aList.Add("haha");
aList.Sort();
aList.Reverse(); // This sorts it in Descending order
if you use something like this it wont work and than you have to implement the IComparable interface:
foreach(ListItem item in _leftListBox.Items)
{
aList.Add(item);
}
aList.Sort();
Tuesday, December 21, 2004
Remving an Item from the ListBox
This code is executed on a button click and used to remove the selected item from the ListBox.
private void _delFromListBox(object sender, EventArgs e)
{
for(int i=_rightListBox.Items.Count-1;i>=0;i--)
{
if(_rightListBox.Items[i].Selected)
{
_rightListBox.Items.Remove(_rightListBox.Items[i]);
}
}
private void _delFromListBox(object sender, EventArgs e)
{
for(int i=_rightListBox.Items.Count-1;i>=0;i--)
{
if(_rightListBox.Items[i].Selected)
{
_rightListBox.Items.Remove(_rightListBox.Items[i]);
}
}
Code room on www.msdn.microsoft.com
Code room is a new pilot in which microsoft chooses 3 developers from one state and they are given a task, software application to build in 5 hours. Its pretty intense and fun to watch.
for more details go to www.msdn.microsoft.com
for more details go to www.msdn.microsoft.com
Thursday, December 16, 2004
String Concatenation
You can easily perform string contatenation like this:
string a = "hello";
string b = " world";
string c = a+b; // c contains hello world
Not a good idea ! Why ? because strings are immutable and everytime you concatenate the new copy of the string is made meaning a new object. So if you want to concatenate two strings use the StringBuilder class append method. StringBuilder has a link list data structure and no new objects are made when concatenation operation is performed.
string a = "hello";
string b = " world";
string c = a+b; // c contains hello world
Not a good idea ! Why ? because strings are immutable and everytime you concatenate the new copy of the string is made meaning a new object. So if you want to concatenate two strings use the StringBuilder class append method. StringBuilder has a link list data structure and no new objects are made when concatenation operation is performed.
Developing Asp.net Server Controls
Starting from December 16 till January 9th 2005. I will be mostly learning how to make WebServer Controls. You can view and buy some of the controls from my website www.azamsharp.cjb.net.
This will take me some sleepless nights but somethings have to be done in certain time.
"Knowledge is power"
This will take me some sleepless nights but somethings have to be done in certain time.
"Knowledge is power"
Friday, December 10, 2004
FireFox kicks IE Butt
All my life I have been installing different softwares so that my IE wont open pop up windows and run faster. The easy solution is to just switch to FireFox browser.
This is the best internet browser I have ever seen.
Download FireFox:
http://www.mozilla.org/products/firefox/
This is the best internet browser I have ever seen.
Download FireFox:
http://www.mozilla.org/products/firefox/
Returning class object or the DataSet
Suppose you have a class:
public class Person
{
private string _name;
private string _code;
public Person()
{
_name = null;
_code = null;
}
public string Name
{
get { return _name; }
}
}
Now there is another class which use the Person class:
public class getDetails
{
Person person = new Person();
getPhoneNumber(person.Name); // This will return the person name
.
.
.
return person // returns the whole Person object
}
Another way of returning the data can be of using DataSet. We query in the database and populate the dataset using the result of that query.
The question is when to use what approach. When we simple want to display the data on the client side we should use dataSet, having said so also remember that dataset can also be traversed but its a tiring process.
On the other hand if we would like to make some calculations on the returned data we can use the return object type approach.
public class Person
{
private string _name;
private string _code;
public Person()
{
_name = null;
_code = null;
}
public string Name
{
get { return _name; }
}
}
Now there is another class which use the Person class:
public class getDetails
{
Person person = new Person();
getPhoneNumber(person.Name); // This will return the person name
.
.
.
return person // returns the whole Person object
}
Another way of returning the data can be of using DataSet. We query in the database and populate the dataset using the result of that query.
The question is when to use what approach. When we simple want to display the data on the client side we should use dataSet, having said so also remember that dataset can also be traversed but its a tiring process.
On the other hand if we would like to make some calculations on the returned data we can use the return object type approach.
Sunday, December 05, 2004
Line breaks in the Xml file while reading the path
my fellow developer found this interesting feature. If you have an Xml file that contains the path to the harddrive. Something like this:
C:\temp\myfile.pdf
This will retrieve the path fine but look the following Xml file:
C:\temp\myfile
.pdf
If you retrieve the path from this xml file you will get something like this in the string.
string filePath = "\r\n"
Which is the code for the return character and the new line character. You should not leave any spaces when specifying the path in the xml file.
This will retrieve the path fine but look the following Xml file:
If you retrieve the path from this xml file you will get something like this in the string.
string filePath = "\r\n"
Which is the code for the return character and the new line character. You should not leave any spaces when specifying the path in the xml file.
Friday, December 03, 2004
Splitting
Here is a simple code to split the UserName from the Domain Name.
One way of doing this:
string s1 = "GEEK/author";
string s2;
int idx = s1.IndexOf('/');
if (idx != -1)
{ s2 = s1.Substring(idx + 1);}
else
{ // do some error handling}
Here is another version of the same code:
private bool IsAuthenticated()
{
// Here get getIdentity simple returns the "GEEK\author"
int indexValue = getIdentity().IndexOf('\\') + 1;
return getIdentity().Substring(indexValue) == AUTHENTICATEDUSER ? true : false;
}
Here is another way:
if(username.endswith("//author"))
{
// Authenticated
}
One way of doing this:
string s1 = "GEEK/author";
string s2;
int idx = s1.IndexOf('/');
if (idx != -1)
{ s2 = s1.Substring(idx + 1);}
else
{ // do some error handling}
Here is another version of the same code:
private bool IsAuthenticated()
{
// Here get getIdentity simple returns the "GEEK\author"
int indexValue = getIdentity().IndexOf('\\') + 1;
return getIdentity().Substring(indexValue) == AUTHENTICATEDUSER ? true : false;
}
Here is another way:
if(username.endswith("//author"))
{
// Authenticated
}
Thursday, December 02, 2004
Disco file code can't be generated
This error is really annoying since it does not really tells whats wrong. Error is generated when you try to make a proxy of your web service which does not contain WebMethods.
So always have one dummy methods before adding a proxy for the client.
So always have one dummy methods before adding a proxy for the client.
Subscribe to:
Comments (Atom)