CodeCharge Studio | All ASP PHP Perl ColdFusion Java C#.NET VB.NET |
The examples below demonstrate the code used when working with controls and HTML snippets contained within Panels, including assigning control values and hiding the panels.
Note that the panel component is transparent when accessing embedded controls' properties and methods, therefore you may set control values using the same code whether components are within a panel or not.
Here is how to assign a value to, or hide a single control that is embedded within a panel. In this example we assume that a label named "UserLogin" is embedded within a panel named "Panel1" that is placed directly on the page (not inside a form). If a user is logged into the system we want to populate the label with the user's name, otherwise we want to hide the panel containing an HTML snippet and the label.
The following HTML code represents the panel structure:
<!-- BEGIN Panel Panel1 --> <table> <tr> <td><Welcome {UserLogin}"></td> </tr> </table> <!-- END Panel Panel1 -->
The following Before Show event code is assigned to the Panel:
Function Panel1_BeforeShow(Sender) If CCGetUserID() Then UserLogin.Value = CCGetUserLogin() Else Panel1.Visible = false End if End Function
function Panel1_BeforeShow(& $sender) { global $Panel1; global $UserLogin; if (CCGetUserID()) { $UserLogin->SetValue(CCGetUserLogin()); } else { $Panel1->Visible = false; } }
sub Panel1_BeforeShow() { if (CCGetUserID()) { $UserLogin->SetValue(CCGetUserLogin()); } else { $Panel1->{Visible} = 0; } }
<!---Event: BeforeShow. Control: Panel1 ---> <CFIF IsDefined("Session.UserID)"> <CFSET fldUserLogin = Session.UserLogin> <CFELSE> <CFSET hidePanel1 = True> </CFIF>
'Panel Panel1 Event BeforeShow. If Not IsNothing(DBUtility.UserID) Then UserLogin.SetValue(DBUtility.UserLogin) Else Panel1.Visible = False End if
//Panel Panel1 Event BeforeShow. if (DBUtility.UserID != null) { UserLogin.SetValue(DBUtility.UserLogin); } else { Panel1.Visible = false; }
//Panel1_BeforeShow String login = Utils.getUserLogin(e.getPage()); if (login != null) { e.getPage().getControl("UserLogin").setValue(login); } else { e.getPanel().setVisible(false); }
Working with multiple controls embedded within a panel is similar to working with a single control.
In this example we assume that two record rows, one with a label named "User_id_assigned_by" and another with a label tasks_start_date" are embedded within a panel named "Panel1". In the insert mode we want to hide both record rows and control, while in the Edit mode we want to assign a custom value to the label User_id_assigned_by. The record form is named "tasks".
The following HTML code represents the panel structure:
<!-- BEGIN Panel Panel1 --> <tr> <td>Assigned By</td> <td><{User_id_assigned_by}"></td> </tr> <tr> <td>Start Date</td> <td><{task_start_date}></td> </tr> <!-- END Panel Panel1 -->
The following Before Show event code is assigned to the "tasks" form:
Function tasks_BeforeShow() If tasks.EditMode Then tasks.user_id_assign_by.Value = CCDLookUp("emp_name", "employees", "emp_id=" &_ DBIntranetDB.ToSQL(tasks.user_id_assign_by.Value, ccsInteger), DBIntranetDB) Else tasks.Panel1.Visible = false End if End Function
function tasks_BeforeShow() { global $tasks; global $DBIntranetDB; if ($tasks->EditMode) { $emp_name = CCDLookUp("emp_name", "employees", "emp_id=". $DBIntranetDB->ToSQL($tasks->user_id_assign_by->GetValue(), ccsInteger), $DBIntranetDB); $tasks->user_id_assign_by->SetValue($emp_name); } else { $tasks->Panel1->Visible = false; } }
sub tasks_BeforeShow() { $DBIntranetDB = clsDBIntranetDB->new(); if ( $tasks->{EditMode} ) { $tasks->{user_id_assign_by}->SetValue(CCDlookUp("emp_name", "employees", " emp_id=" . $DBIntranetDB->ToSQL($tasks->{user_id_assign_by}->GetValue(), $ccsInteger),$DBIntranetDB)); } else { $tasks->{Panel1}->{Visible} = 0; } }
<!---Event: BeforeShow. Control: tasks ---> <CFIF blnEditModeTasks> <CF_CCToSQL Value= "#flduser_id_assign_by#" Type= "#ccsInteger#" > <CF_CCDLookUp Field="emp_name" Table="employees" Where="emp_id=#CCToSQL#" Connection="IntranetDB"> <CFSET flduser_id_assign_by=CCDLookUp> <CFELSE> <CFSET hidePanel1 = True> </CFIF>
'Record tasks Event BeforeShow. Dim NewDao As DataAccessObject = Settings.IntranetDBDataAccessObject If IsInsertMode = True Then TasksPanel1.Visible = False Else tasksuser_id_assign_by.Text = Convert.ToString(NewDao.ExecuteScalar( _ "SELECT emp_name FROM employees WHERE emp_id="& _ Convert.ToString( tasksuser_id_assign_by.Text))) End if
//Record tasks Event BeforeShow. DataAccessObject NewDao = Settings.IntranetDBDataAccessObject; if (IsInsertMode) { TasksPanel1.Visible = false; } else { SqlCommand userNameCmd = new SqlCommand( "SELECT emp_name FROM employees " + "WHERE emp_id=" + NewDao.ToSql(item.user_id_assign_by.GetFormattedValue, FieldType.Integer), NewDao); tasksuser_id_assign_by.Text = userNameCmd.ExecuteScalar().ToString(); }
//tasks_BeforeShow if (e.getRecord().isEditMode()) { e.getControl().setValue(DBTools.dLookUp("emp_name", "employees", "emp_id=" + DBTools.toSql(e.getControl().getFormattedValue(),JDBCConnection.INTEGER,"IntranetDB"), "IntranetDB")); } else { e.getRecord().getControl("Panel1").setVisible(false); }
In this example we hide sample panels that contain only HTML code and no controls. The following HTML code represents the panel structure:
<!-- BEGIN Panel Panel1 --> <table> <tr> <td>Welcome to our site</td> </tr> <tr> <td> <!-- BEGIN Panel Panel2 --> <table> <tr> <td>Administration</td> </tr> </table> <!-- END Panel Panel2 --> </td> </tr> </table> <!-- END Panel Panel1 -->
Note: to embed an HTML section within a panel, select an HTML code, then click on the panel icon on the Forms tab of the Toolbox.
The following Before Show event code is assigned to the panel:
Function Panel1_BeforeShow() Panel1.Visible = false End Function2. Includable page level, where panels are placed on an includable page called "header".
Function header_Panel1_BeforeShow() header.Panel1.Visible = false End Function3. Form level, where panels are placed inside a record form called 'messages',
Function messages_Panel1_BeforeShow() messages.Panel1.Visible = false End Function4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
Function Panel2_BeforeShow() Panel2.Visible = false End Function
function Panel1_BeforeShow() { global $Panel1; $Panel1->Visible = false; }2. Includable page level, where panels are placed on an includable page called "header".
function header_Panel1_BeforeShow() { global $header; $header->Panel1->Visible = false; }3. Form level, where panels are placed inside a record form called 'messages',
function messages_Panel1_BeforeShow() { global $messages; $messages->Panel1->Visible = false; }4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
function Panel2_BeforeShow() { global $Panel2; $Panel2->Visible = false; }
sub Panel1_BeforeShow() { $Panel1->{Visible} = 0; }2. Includable page level, where panels are placed on an includable page called "header".
sub header_Panel1_BeforeShow() { $header->{Panel1}->{Visible} = 0; }3. Form level, where panels are placed inside a record form called 'messages',
sub messages_Panel1_BeforeShow() { $messages->{Panel1}->{Visible} = 0; }4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
sub Panel2_BeforeShow() { $Panel2->{Visible} = 0; }
<!---Event: BeforeShow. Control: NewPage1 ---> <CFSET hidePanel1 = True>2. Includable page level, where panels are placed on an includable page called "header".
<!---Event: BeforeShow. Control: header ---> <CFSET hidePanel1 = True>3. Form level, where panels are placed inside a record form called 'messages',
<!---Event: BeforeShow. Control: messages ---> <CFSET hidePanel1 = True>4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
<!---Event: BeforeShow. Control: Panel2 ---> <CFSET hidePanel2 = True>
'Page NewPage1 Event BeforeShow. Panel1.Visible = False2. Includable page level, where panels are placed on an includable page called "header".
'Page header Event BeforeShow. Panel1.Visible = False3. Form level, where panels are placed inside a record form called 'messages',
'Record messages Event BeforeShow. messagesPanel1.Visible = False4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
'Panel Panel2 Event BeforeShow. Panel2.Visible = False
//Page NewPage1 Event BeforeShow. Panel1.Visible = false;2. Includable page level, where panels are placed on an includable page called "header".
//Page header Event BeforeShow. Panel1.Visible = false;3. Form level, where panels are placed inside a record form called 'messages',
//Record messages Event BeforeShow. messagesPanel1.Visible = false;4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
//Panel Panel2 Event BeforeShow. Panel2.Visible = false;
//page_BeforeShow e.getPage().getPanel("panel1").setVisible(false);2. Includable page level, where panels are placed on an includable page called "header".
//header_BeforeShow e.getPage().getPanel("Panel1").setVisible(false);3. Form level, where panels are placed inside a record form called 'messages',
//messages_BeforeShow e.getRecord().getPanel("Panel1").setVisible(false);4. Nested panels, where 'Panel2' is placed within 'Panel1'. The event code can be assigned to either 'Panel1' or 'Panel2'.
//Panel2_BeforeShow e.getPage().getPanel("Panel2").setVisible(false);