From 1e809a0a05e40786fafdb2002c7ceda8573b3f8e Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 6 Dec 2005 15:20:50 +0000 Subject: --- framework/Web/UI/WebControls/TLinkButton.php | 166 ++++++++++----------------- 1 file changed, 60 insertions(+), 106 deletions(-) (limited to 'framework/Web/UI/WebControls/TLinkButton.php') diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php index 74feb9db..517a2f8b 100644 --- a/framework/Web/UI/WebControls/TLinkButton.php +++ b/framework/Web/UI/WebControls/TLinkButton.php @@ -14,55 +14,45 @@ * TLinkButton class * * TLinkButton creates a hyperlink style button on the page. - * TLinkButton has the same appearance as a hyperlink. However, it is only - * used to submit data to the same page. If you want to link to another Web page - * when the component is clicked, consider using the THyperLink component. - * Like TButton, you can create either a submit button or a command button. + * TLinkButton has the same appearance as a hyperlink. However, it is mainly + * used to submit data to a page. Like {@link TButton}, you can create either + * a submit button or a command button. * - * A command button has a command name (specified by the CommandName property) - * and a command parameter (specified by CommandParameter property) - * associated with the button. This allows you to create multiple TLinkButton components - * on a Web page and programmatically determine which one is clicked with what parameter. - * You can provide an event handler for the OnCommand event to programmatically control - * the actions performed when the command button is clicked. - * In the event handler, you can also determine - * the CommandName property value and the CommandParameter property value - * through name and parameter of the event parameter which is of - * type TCommandEventParameter. + * A command button has a command name (specified by + * the {@link setCommandName CommandName} property) and and a command parameter + * (specified by {@link setCommandParameter CommandParameter} property) + * associated with the button. This allows you to create multiple TLinkButton + * components on a Web page and programmatically determine which one is clicked + * with what parameter. You can provide an event handler for + * {@link onCommand Command} event to programmatically control the actions performed + * when the command button is clicked. In the event handler, you can determine + * the {@link setCommandName CommandName} property value and + * the {@link setCommandParameter CommandParameter} property value + * through the {@link TCommandParameter::getName Name} and + * {@link TCommandParameter::getParameter Parameter} properties of the event + * parameter which is of type {@link TCommandEventParameter}. * * A submit button does not have a command name associated with the button * and clicking on it simply posts the Web page back to the server. * By default, a TLinkButton component is a submit button. - * You can provide an event handler for the OnClick event to programmatically - * control the actions performed when the submit button is clicked. + * You can provide an event handler for the {@link onClick Click} event + * to programmatically control the actions performed when the submit button is clicked. * - * TLinkButton will display the Text property value as the hyperlink text. If Text - * is empty, the body content of TLinkButton will be displayed. - * Therefore, you can use TLinkButton as an image button by enclosing an 'img' tag - * as the body of TLinkButton. + * By default, clicking on a TLinkButton will cause input validation (if any) + * to be performed. You can turn this on or off by setting + * the {@link setCausesValidation CausesValidation} property. + * If validation is successful, the data will be post back to the same page. + * You can change the postback target by setting the {@link setPostBackUrl PostBackUrl} + * property. * - * Note, Text will be HTML encoded before it is displayed in the TLinkButton component. - * If you don't want it to be so, set EncodeText to false. + * To set the client-side javascript associated with the user's click action, + * use the {@link setOnClientClick OnClientClick} property. The value will be rendered + * as the onclick attribute of the link button. * - * Namespace: System.Web.UI.WebControls - * - * Properties - * - Text, string, kept in viewstate - *
Gets or sets the text caption displayed in the TLinkButton component. - * - EncodeText, boolean, default=true, kept in viewstate - *
Gets or sets the value indicating whether Text should be HTML-encoded when rendering. - * - CausesValidation, boolean, default=true, kept in viewstate - *
Gets or sets a value indicating whether validation is performed when the TLinkButton component is clicked. - * - CommandName, string, kept in viewstate - *
Gets or sets the command name associated with the TLinkButton component that is passed to - * the OnCommand event. - * - CommandParameter, string, kept in viewstate - *
Gets or sets an optional parameter passed to the OnCommand event along with - * the associated CommandName. - * - * Events - * - OnClick Occurs when the TLinkButton component is clicked. - * - OnCommand Occurs when the TLinkButton component is clicked. + * TLinkButton will display the {@link setText Text} property value + * as the hyperlink text. If {@link setText Text} is empty, the body content + * of TLinkButton will be displayed. Therefore, you can use TLinkButton + * as an image button by enclosing an <img> tag as the body of TLinkButton. * * @author Qiang Xue * @version $Revision: $ $Date: $ @@ -91,20 +81,14 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):''; $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick()); if(!empty($onclick)) - $writer->addAttribute('onclick',$onclick); + $writer->addAttribute('onclick','javascript:'.$onclick); // We call parent implementation here because some attributes // may be overwritten in the following parent::addAttributesToRender($writer); if($this->getEnabled(true)) - { - if(($options=$this->getPostBackOptions())===null) - $href='javascript:void(0)'; - else - $href=$page->getClientScript()->getPostBackEventReference($this,'',$options,true); - $writer->addAttribute('href',$href); - } + $writer->addAttribute('href',$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),true)); else if($this->getEnabled()) // in this case, parent will not render 'disabled' $writer->addAttribute('disabled','disabled'); } @@ -116,17 +100,20 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler */ protected function getPostBackOptions() { + $flag=false; $options=new TPostBackOptions(); - $options->ClientSubmit=true; - $page=$this->getPage(); - if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount()>0) + if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0) { - $options->PerformValidation=true; - $options->ValidationGroup=$this->getValidationGroup(); + $flag=true; + $options->setPerformValidation(true); + $options->setValidationGroup($this->getValidationGroup()); } if($this->getPostBackUrl()!=='') - $options->ActionUrl=THttpUtility::quoteJavaScriptString($this->getPostBackUrl()); - return $options; + { + $flag=true; + $options->setActionUrl($this->getPostBackUrl()); + } + return $flag?$options:null; } /** @@ -260,26 +247,27 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler } /** - * Raises postback event. - * The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand) - * indicating the component is responsible for the postback event. - * This method is primarily used by framework developers. - * @param string the parameter associated with the postback event + * Raises the postback event. + * This method is required by {@link IPostBackEventHandler} interface. + * If {@link getCausesValidation CausesValidation} is true, it will + * invoke the page's {@link TPage::validate validate} method first. + * It will raise {@link onClick Click} and {@link onCommand Command} events. + * This method is mainly used by framework and control developers. + * @param TEventParameter the event parameter */ public function raisePostBackEvent($param) { - $this->onClick(new TEventParameter); - $cmdParam=new TCommandEventParameter; - $cmdParam->name=$this->getCommandName(); - $cmdParam->parameter=$this->getCommandParameter(); - $this->onCommand($cmdParam); + if($this->getCausesValidation()) + $this->getPage()->validate($this->getValidationGroup()); + $this->onClick(null); + $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter())); } /** - * This method is invoked when the component is clicked. - * The method raises 'OnClick' event to fire up the event delegates. + * This method is invoked when the button is clicked. + * The method raises 'Click' event to fire up the event handlers. * If you override this method, be sure to call the parent implementation - * so that the event delegates can be invoked. + * so that the event handler can be invoked. * @param TEventParameter event parameter to be passed to the event handlers */ public function onClick($param) @@ -288,10 +276,10 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler } /** - * This method is invoked when the component is clicked. - * The method raises 'OnCommand' event to fire up the event delegates. + * This method is invoked when the button is clicked. + * The method raises 'Command' event to fire up the event handlers. * If you override this method, be sure to call the parent implementation - * so that the event delegates can be invoked. + * so that the event handlers can be invoked. * @param TCommandEventParameter event parameter to be passed to the event handlers */ public function onCommand($param) @@ -299,40 +287,6 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler $this->raiseEvent('Command',$this,$param); $this->raiseBubbleEvent($this,$param); } - - /** - * This overrides the parent implementation by rendering more TLinkButton-specific attributes. - * @return ArrayObject the attributes to be rendered - */ - protected function getAttributesToRender() - { - $attr=parent::getAttributesToRender(); - if($this->isEnabled()) - { - $page=$this->getPage(); - $postBack=$page->getPostBackClientEvent($this,''); - if($this->causesValidation() && $this->Page->isEndScriptRegistered('TValidator')) - { - $group = $this->getValidationGroup(); - $group = strlen($group) ? ",'".$group."'" : ''; - $script = "Prado.Validation.AddTarget('{$this->ClientID}' {$group});"; - $this->Page->registerEndScript($this->ClientID.'target', $script); - } - - $attr['href']="javascript:{$postBack}"; - } - return $attr; - } - - /** - * This overrides the parent implementation by rendering either Text or the body contents. - * @return string the rendering result - */ - protected function renderBody() - { - $text=$this->isEncodeText()?pradoEncodeData($this->getText()):$this->getText(); - return strlen($text)?$text:parent::renderBody(); - } } ?> \ No newline at end of file -- cgit v1.2.3