2021年10月24日 星期日

CodeCharge Studio 的 子網頁裡面的 Panel 的參照

一個子網頁(被 include 的子網頁),它裡面的 Panel ,要被參照,例如 visible

應該這樣用:

global $page;

$page->control->Visible = false;

$page->panel->Visible = false;


不可以這樣:

global $panel;

$panel->Visible = true;


這個問題,我經常弄錯,紀錄在這裡,提醒自己。


但是,如果是子網頁page -> 子網頁subpage -> Panel 

就不能再這樣用了!

function subpage_BeforeShow(& $sender)

global $subpage;

$subpage->control->Visible = false;

$subpage->panel->Visible = false;



比較困擾的應該是因為 Panel 是透明的,無法直接用 global $Panel1;這種方式

此時,只能使用 $Component 這個變數了!

例如:

function navside_BeforeShow(& $sender)

{

    $navside_BeforeShow = true;

    $Component = & $sender;

    $Container = & CCGetParentContainer($sender);

    global $navside; //Compatibility

//End navside_BeforeShow


//Custom Code @17-2A29BDB7

// -------------------------

    // Write your own code here.

    

           $db = new clsDBconn_mysql();

$SQL = "SELECT is_fund_opened(".

             $db->ToSQL($_SESSION["UserID"], ccsInteger) .

             ") as v_opened;";

$sql_log = "CALL system_log(".$db->ToSQL($SQL, ccsText).")";

$db->query($sql_log);

$db->query($SQL);

$result = $db->next_record();

if ($db->f("v_opened")==0) {

    $Component->Panel1->Visible = True;

    $Component->Panel2->Visible = False;

} else {

    $Component->Panel1->Visible = False;

    $Component->Panel2->Visible = True;

}


    

    $db->close();

    

    

// -------------------------

//End Custom Code


//Close navside_BeforeShow @1-E75A1C39

    return $navside_BeforeShow;

}


這一段 CCS 自己的說明,要好好看看:

Referencing Objects

The objects in the Web applications generated by CodeCharge Studio can be referenced in a variety of ways. In many cases, to work with a specific object within a program you will need to know its position within the program hierarchy. For example, an object that is placed directly on the page may need to be addressed differently compared to an object placed within a form (which is also an object).

ASP

Examples of working with objects Syntax
Form object placed on a page Page Events <form>.Visible = False
Form Events EventCaller.Visible = False
Control object placed within a form Page Events <form>.<control>.Value = "123"
Form Events EventCaller.<control>.Value = "123"
Control Events EventCaller.Value = "123"
Control object placed on a page Page Events <control>.Value = "ABC"
Control Events EventCaller.Value = "ABC"
Control object placed on an included page Main Page Events <page>.<control>.Visible = False
Includable Page Events EventCaller.<control>.Visible = False
Control Events EventCaller.Visible = False
Form object placed on an included page Main Page Events <page>.<form>.Visible = False
Includable Page Events EventCaller.<form>.Visible = False
Form Events EventCaller.Visible = False
Control object placed in a form within an  included page  Main Page Events <page>.<form>.<control>.Visible = False
Includable Page Events EventCaller.<form>.<control>.Visible = False
Form Events EventCaller.<control>.Visible = False
Control Events EventCaller.Visible = False

Note: Using EventCaller is recommended when planning to reuse the event code since it doesn't require referring to objects by name.

Perl

Examples of working with objects Syntax
Form object placed on a page $<form>->{Visible} = 0;
Control object placed within a form $<form>->{<control>}->SetValue("123");
Control object placed on a page $<control>->SetValue("ABC");
Control object placed on an included page $<page>->{<control>}->{Visible} = 0;
Form object placed on an included page $<page>->{<form>}->{Visible} = 0;
Control object placed in a form within an included page  $<page>->{<form>}->{<control>}->{Visible} = 0;
Assigning an object to a variable $<variable> = $<object>;

Java

Examples of working with objects Syntax
Form object placed on a page Page Events e.getPage().getComponent("<form>").setVisible(false);
Form Events e.getComponent().setVisible(false);
Control object placed within a form Page Events e.getPage().getComponent("<form>").getControl("<control>").setValue("123");
Form Events e.getComponent().getControl("<control>").setValue("123");
Control Events e.getControl().setValue("123");
Control object placed on a page Page Events e.getPage().getControl("<control>").setValue("ABC");
Control Events e.getControl().setValue("ABC");
Assigning an object to a variable <variable> = <object>;

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

C#

Examples of working with objects Syntax
Form object placed on a page Grid and Editable Grid Events <form>Repeater.Visible = false;
Record Events <form>Holder.Visible = false;
Directory and Path Events <form>.Visible = false;
Control object placed within a Record form <form><control>.Visible = false;
Control object placed within a Grid, Editable Grid, Directory and Path form Control's Before Show Event <form><control>.Visible = false;
Form's Before Show and Before Show Row Event Object reference should be retrieved from the FormControls collection.
See the ItemDataBound Event MSDN example.
Control object placed on a page <control>.Visible = false;
Assigning an object to a variable <variable> = <object>;

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

VB.Net

Examples of working with objects Syntax
Form object placed on a page Grid and Editable Grid Events <form>Repeater.Visible = False
Record Events <form>Holder.Visible = False
Directory and Path Events <form>.Visible = False
Control object placed within a Record form <form><control>.Visible = False
Control object placed within a Grid, Editable Grid, Directory and Path form Control's Before Show Event <form><control>.Visible = False
Form's Before Show and Before Show Row Event Object reference should be retrieved from the FormControls collection.
See the ItemDataBound Event MSDN example.
Control object placed on a page <control>.Visible = False
Assigning an object to a variable <variable> = <object>

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

ColdFusion

Examples of working with objects Syntax
Form variable placed on a page or within a form <CFSET blnReadAllowed<form>=false>
Control variable placed within a form or a page <CFSET fld<control> = "abc">

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above.

PHP

When using PHP you can address objects in a generic way as $Component to refer to the component raising the event, and $Container to refer to the host form of $Component. This method of referring to objects is recommended to make the event code reusable since it doesn't require referring to objects by name. You can also refer to objects using global variables, for example use $MyGrid to refer to 'MyGrid' grid.

Examples of working with objects in a generic way Syntax
Form object placed on a page Page Events $Component->form->visible = false;
Form Events $Component->Visible = false;
Control object placed within a form Page Events $Component->form->control->SetValue($Component->form->PageNumber);
Form Events $Component->control->SetValue($Component->PageNumber);
Control Events $Component->SetValue($Container->PageNumber);
Control object placed on a page Page Events $Component->control->SetValue("ABC");
Control Events $Component->SetValue("ABC");
Control object placed on an included page Main Page Events $Component->page->control->Visible = false;
Includable Page  Events $Component->control->Visible = false;
Control Events $Component->Visible = false;
Form object placed on an included page Main Page Events $Component->page->form->Visible = false;
Includable Page  Events $Component->form->Visible = false;
Form Events $Component->Visible = false;
Control object placed in a form within an  included page  Main Page Events $Component->page->form->control->Visible = false;
Includable Page  Events $Component->form->control->Visible = false;
Form Events $Component->control->Visible = false;
Control Events $Component->Visible = false;


Examples of working with objects using global variables Syntax
Form object placed on a page $form->Visible = false;
Control object placed within a form $form->control->SetValue("123");
Control object placed on a page $control->SetValue("ABC");
Control object placed on an included page $page->control->Visible = false;
Form object placed on an included page $page->form->Visible = false;
Control object placed in a form within an  included page  $page->form->control->Visible = false;



沒有留言:

張貼留言

如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。