diff --git a/pgadmin/dlg/dlgProperty.cpp b/pgadmin/dlg/dlgProperty.cpp
index 7312e97..1e8427a 100644
--- a/pgadmin/dlg/dlgProperty.cpp
+++ b/pgadmin/dlg/dlgProperty.cpp
@@ -98,6 +98,8 @@ BEGIN_EVENT_TABLE(dlgProperty, DialogWithHelp)
 	EVT_BUTTON(wxID_HELP,                           dlgProperty::OnHelp)
 	EVT_BUTTON(wxID_OK,                             dlgProperty::OnOK)
 	EVT_BUTTON(wxID_APPLY,                          dlgProperty::OnApply)
+	EVT_BUTTON(wxID_CANCEL,                         dlgProperty::OnCancel)
+	EVT_CLOSE (                                     dlgProperty::OnClose)
 END_EVENT_TABLE();
 
 
@@ -233,6 +235,26 @@ void dlgProperty::EnableOK(bool enable)
 	}
 }
 
+void dlgProperty::OnClose(wxCloseEvent &ev)
+{
+	// Sets the window pointer to NULL when dialog gets closed
+	if (GetObject())
+	{
+		GetObject()->SetWindowPtr(NULL);
+	}
+	pgDialog::OnClose(ev);
+}
+
+void dlgProperty::OnCancel(wxCommandEvent &ev)
+{
+	// Sets the window pointer to NULL when dialog gets closed
+	if (GetObject())
+	{
+		GetObject()->SetWindowPtr(NULL);
+	}
+	pgDialog::OnCancel(ev);
+}
+
 
 void dlgProperty::SetSqlReadOnly(bool readonly)
 {
@@ -826,10 +848,15 @@ void dlgProperty::ShowObject()
 				ownDialog = data->GetWindowPtr();
 				data->SetWindowPtr(NULL);
 			}
-			mainForm->Refresh(tblobj);
-			if (data)
+			// Refresh call creates the new data object so we will use the newly
+			// created object and sets the window pointer of the newly created object to NULL.
+			// Also we have set the dialogs's object to the newly created object.
+			pgObject *newData = mainForm->Refresh(tblobj);
+			if (newData)
 			{
-				data->SetWindowPtr(ownDialog);
+				newData->SetWindowPtr(NULL);
+				if (ownDialog)
+					ownDialog->SetObject(newData);
 			}
 		}
 
@@ -973,6 +1000,11 @@ bool dlgProperty::apply(const wxString &sql, const wxString &sql2)
 	}
 
 	ShowObject();
+	// In case of apply we need to set the window pointer of the object to the current window.
+	if (GetObject())
+	{
+		GetObject()->SetWindowPtr(this);
+	}
 
 	return true;
 }
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index 4b8db5a..0793b37 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -515,7 +515,7 @@ void frmMain::CreateMenus()
 }
 
 
-void frmMain::Refresh(pgObject *data)
+pgObject * frmMain::Refresh(pgObject *data)
 {
 	bool done = false;
 	pgObject *obj = NULL;
@@ -577,7 +577,7 @@ void frmMain::Refresh(pgObject *data)
 				{
 					CheckAlive();
 					browser->Thaw();
-					return;
+					return data;
 				}
 
 				wxTreeItemId delItem = currentItem;
@@ -600,6 +600,8 @@ void frmMain::Refresh(pgObject *data)
 
 	browser->Thaw();
 	EndMsg(done);
+
+	return currentObject;
 }
 
 void frmMain::OnCopy(wxCommandEvent &ev)
diff --git a/pgadmin/include/dlg/dlgFunction.h b/pgadmin/include/dlg/dlgFunction.h
index 3c2886d..ccd7c0a 100644
--- a/pgadmin/include/dlg/dlgFunction.h
+++ b/pgadmin/include/dlg/dlgFunction.h
@@ -32,6 +32,8 @@ public:
 	void SetObject(pgObject *obj)
 	{
 		function = (pgFunction *)obj;
+		if(seclabelPage)
+			seclabelPage->SetObject(obj);
 	}
 
 	wxString GetHelpPage(bool forCreate) const
diff --git a/pgadmin/include/dlg/dlgProperty.h b/pgadmin/include/dlg/dlgProperty.h
index e821b53..db021b1 100644
--- a/pgadmin/include/dlg/dlgProperty.h
+++ b/pgadmin/include/dlg/dlgProperty.h
@@ -125,6 +125,9 @@ protected:
 	{
 		return true;
 	};
+	void OnClose(wxCloseEvent &ev);
+	void OnCancel(wxCommandEvent &ev);
+
 	void ShowObject();
 
 	void FillSQLTextfield();
diff --git a/pgadmin/include/dlg/dlgView.h b/pgadmin/include/dlg/dlgView.h
index 1cb723e..a66ea55 100644
--- a/pgadmin/include/dlg/dlgView.h
+++ b/pgadmin/include/dlg/dlgView.h
@@ -34,6 +34,8 @@ public:
 	void SetObject(pgObject *obj)
 	{
 		view = (pgView *)obj;
+		if(seclabelPage)
+			seclabelPage->SetObject(obj);
 	}
 
 private:
diff --git a/pgadmin/include/frm/frmMain.h b/pgadmin/include/frm/frmMain.h
index cff48e2..bb11315 100644
--- a/pgadmin/include/frm/frmMain.h
+++ b/pgadmin/include/frm/frmMain.h
@@ -103,7 +103,7 @@ public:
 	bool CheckAlive();
 
 	void execSelChange(wxTreeItemId item, bool currentNode);
-	void Refresh(pgObject *data);
+	pgObject * Refresh(pgObject *data);
 	void ExecDrop(bool cascaded);
 	void ShowObjStatistics(pgObject *data, wxWindow *ctrl = NULL);
 
