Here is a link to a nice discussion on a problem faced by a user who wants to connect his client software to a server that doesnt have a static IP address
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22919918.html
There is a reference to some nice and FREE online utilities (DynDNS) that are worth noting.
Friday, October 26, 2007
Wednesday, October 24, 2007
Event does not fire unless control is created in memory
I stumbled across a very interesting problem in ASP.net. Say you have one Repeater and you have put a LinkButton for a cell in every row. The LinkButton has a eventHandler for its onClick method. The interesting thing is that, the click event will not be fired unless the linkbutton inside the repeater control is recreated.
It means that unless you repopulate the repeater which will create a linkButton in every row, the click event will not be evaluated. This is happening because, unless the server controls (here the linkbutton) is created in the memory, the click event cannot be tied to the control.
To test this, just populate a repeater control with linkbutton in the load event only when the page is loaded for the first time as in the following statment
if (!isPostback)
{
//Fill the repeater
}
//Write event handler to handle click event of the linkbutton
The above will cause the repeater control to appear on the page. After this, click the link button. You will see that the Click Event handler is not fired because the data has not been bound to the repeater and therefore no linkbutton exist.
It means that unless you repopulate the repeater which will create a linkButton in every row, the click event will not be evaluated. This is happening because, unless the server controls (here the linkbutton) is created in the memory, the click event cannot be tied to the control.
To test this, just populate a repeater control with linkbutton in the load event only when the page is loaded for the first time as in the following statment
if (!isPostback)
{
//Fill the repeater
}
//Write event handler to handle click event of the linkbutton
The above will cause the repeater control to appear on the page. After this, click the link button. You will see that the Click Event handler is not fired because the data has not been bound to the repeater and therefore no linkbutton exist.
Sunday, October 21, 2007
Value type and reference type differences
I have been reading a lot about the differences between value type and reference type elsewhere in the internet. The concept is simple if tried to understand the memory allocation for these two in the memory. A value type is allocated in a stack (first in last out fashion). A reference type object is allocated in a heap and a reference object to this space in the heap is allocated in the stack.
Then interesting thing is that once this reference to the heap goes out of scope how does the stuff in heap get cleaned. This is where the garbage collector comes into action. I read a nice article on albahari's (http://www.albahari.com/value%20vs%20reference%20types.html) web site that tells us how to get these space de-alllocated automatically from the heap.
If an object can be added to a container that is aware about its job to clean or destroy all its children then we do not need an exclusive call to the dispose method of the object itself.
For example if we create a text box, we need to first add it to the container control. Now when the form itself gets destroyed, it will automatically remove the textbox details from the heap!.
This means that if we create a text box like in the following statment
TextBox myText= new TextBox();
myForm.Controls.Add(myText);
myText = null;
In the above code the text box does not get destroy even though we have assigned null value to myText reference object. The GB will detect that the textbox in the heap is being referenced by the Form! (myForm.Controls.Add())
Then interesting thing is that once this reference to the heap goes out of scope how does the stuff in heap get cleaned. This is where the garbage collector comes into action. I read a nice article on albahari's (http://www.albahari.com/value%20vs%20reference%20types.html) web site that tells us how to get these space de-alllocated automatically from the heap.
If an object can be added to a container that is aware about its job to clean or destroy all its children then we do not need an exclusive call to the dispose method of the object itself.
For example if we create a text box, we need to first add it to the container control. Now when the form itself gets destroyed, it will automatically remove the textbox details from the heap!.
This means that if we create a text box like in the following statment
TextBox myText= new TextBox();
myForm.Controls.Add(myText);
myText = null;
In the above code the text box does not get destroy even though we have assigned null value to myText reference object. The GB will detect that the textbox in the heap is being referenced by the Form! (myForm.Controls.Add())
Subscribe to:
Posts (Atom)