From 64d353d1680539fdf3c2d57150f3e93f9f45d84f Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 21 Jan 2006 22:20:51 +0000 Subject: Fixed TImageButton about postbackoptions. --- framework/Web/UI/WebControls/TButton.php | 14 ++++-- framework/Web/UI/WebControls/TImageButton.php | 62 ++++++++++++++------------- 2 files changed, 42 insertions(+), 34 deletions(-) (limited to 'framework') diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index 968a783a..b8956739 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -75,12 +75,14 @@ class TButton extends TWebControl implements IPostBackEventHandler if($this->getEnabled(true)) { if($this->canCauseValidation()) + { + $writer->addAttribute('id',$this->getClientID()); $this->getPage()->getClientScript()->registerPostBackControl($this); + } } else if($this->getEnabled()) // in this case, parent will not render 'disabled' $writer->addAttribute('disabled','disabled'); - $writer->addAttribute('id',$this->getClientID()); parent::addAttributesToRender($writer); } @@ -89,9 +91,13 @@ class TButton extends TWebControl implements IPostBackEventHandler */ protected function canCauseValidation() { - $group = $this->getValidationGroup(); - $hasValidators = $this->getPage()->getValidators($group)->getCount()>0; - return $this->getCausesValidation() && $hasValidators; + if($this->getCausesValidation()) + { + $group=$this->getValidationGroup(); + return $this->getPage()->getValidators($group)->getCount()>0; + } + else + return false; } /** diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php index dfa1752c..72a7df61 100644 --- a/framework/Web/UI/WebControls/TImageButton.php +++ b/framework/Web/UI/WebControls/TImageButton.php @@ -89,32 +89,41 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven $writer->addAttribute('name',$uniqueID); if($this->getEnabled(true)) { - $scripts = $this->getPage()->getClientScript(); - $options = $this->getPostBackOptions(); - $postback = $scripts->getPostBackEventReference($this, '', $options, false); - $scripts->registerClientEvent($this, "click", $postback); + if($this->canCauseValidation()) + { + $writer->addAttribute('id',$this->getClientID()); + $this->getPage()->getClientScript()->registerPostBackControl($this); + } } else if($this->getEnabled()) // in this case, parent will not render 'disabled' $writer->addAttribute('disabled','disabled'); parent::addAttributesToRender($writer); } + /** + * @return boolean whether to perform validation if the button is clicked + */ + protected function canCauseValidation() + { + if($this->getCausesValidation()) + { + $group=$this->getValidationGroup(); + return $this->getPage()->getValidators($group)->getCount()>0; + } + else + return false; + } + /** * Returns postback specifications for the button. * This method is used by framework and control developers. - * @return TPostBackOptions parameters about how the button defines its postback behavior. + * @return array parameters about how the button defines its postback behavior. */ public function getPostBackOptions() { - $options=new TPostBackOptions(); - if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0) - { - $options->setPerformValidation(true); - $options->setValidationGroup($this->getValidationGroup()); - } - if($this->getPostBackUrl()!=='') - $options->setActionUrl($this->getPostBackUrl()); - $options->setClientSubmit(false); + $options['CausesValidation'] = $this->getCausesValidation(); + $options['ValidationGroup'] = $this->getValidationGroup(); + return $options; } @@ -253,22 +262,6 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven $this->setViewState('ValidationGroup',$value,''); } - /** - * @return string the URL of the page to post to when the button is clicked, default is empty meaning post to the current page itself - */ - public function getPostBackUrl() - { - return $this->getViewState('PostBackUrl',''); - } - - /** - * @param string the URL of the page to post to from the current page when the button is clicked, empty if post to the current page itself - */ - public function setPostBackUrl($value) - { - $this->setViewState('PostBackUrl',$value,''); - } - /** * @return string caption of the button */ @@ -297,6 +290,15 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven parent::onPreRender($param); $this->getPage()->registerRequiresPostData($this); } + + /** + * Renders the body content enclosed between the control tag. + * This overrides the parent implementation with nothing to be rendered. + * @param THtmlWriter the writer used for the rendering purpose + */ + protected function renderContents($writer) + { + } } /** -- cgit v1.2.3