Nov 16th, 2008 | 1 Comment

Many a times you need to delete the record but at the same time you need to make sure all the related or referenced records are also deleted. This is because you can not delete a record if it is referenced in another table. In this case you can either delete the referenced record or you can set the “Cascade Delete On”.

Here is the code to implement cascade delete in SQL

ALTER TABLE B  ADD (
CONSTRAINT FK_1 FOREIGN KEY (PARENT_ID)
REFERENCES A (ID) ON DELETE CASCADE)

This code will delete all the referenced records on deletion of primary record. You can use this because deleting the referenced records becomes very tedious at times.

Similar to Cascade Delete there is also Cascade Update. For that stay tuned for my next post :) .

Written by Ajay Matharu

November 16th, 2008 at 7:28 am

Nov 14th, 2008 | 1 Comment

Assume in the master page, we have a user control which we need to access and set its visiblity from content page. We create a public property in the master page called controlVisiblity

public bool LoginControlVisible
{
get
{
return LoginControl.Visible;
}
set
{
LoginControl.Visible = value;
}
}

To gain access to the master page file from the content page, you just need to add the below directive to the content page

<%@ MasterType VirtualPath=”~/siteMaster.master”%>

When ASP.NET realizes the existance of this directive, it generates a strongly typed property “Master”. this property will give you access to the MasterPage file. So directly in the content page code behind you would use the below instead of trying to use the FindControl method.

Master.LoginControlVisible = true;

or

Master.LoginControlVisible = false;

Written by Ajay Matharu

November 14th, 2008 at 2:47 pm