summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TLinkButton.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/WebControls/TLinkButton.php')
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php63
1 files changed, 34 insertions, 29 deletions
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index dd2d8cb7..3ddb6f68 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -46,10 +46,6 @@
* You can change the postback target by setting the {@link setPostBackUrl PostBackUrl}
* property.
*
- * 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 <b>onclick</b> attribute of the link button.
- *
* 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
@@ -79,19 +75,41 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
{
$page=$this->getPage();
$page->ensureRenderInForm($this);
- $onclick=$this->removeAttribute('onclick');
- $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
- if(!empty($onclick))
- $writer->addAttribute('onclick','javascript:'.$onclick);
+
+ $writer->addAttribute('id',$this->getClientID());
// We call parent implementation here because some attributes
// may be overwritten in the following
parent::addAttributesToRender($writer);
+
+ if($this->getEnabled())
+ {
+ $url = $this->getPostBackUrl();
+ //create unique no-op url references
+ $nop = "javascript:;//{$this->ClientID}";
+ $writer->addAttribute('href', $url ? $url : $nop);
+ }
+ else// in this case, parent will not render 'disabled'
+ $writer->addAttribute('disabled','disabled');
+ }
+ /**
+ * Registers the postback javascript code.
+ * If you override this method, be sure to call the parent implementation
+ * so that the event handlers can be invoked.
+ * @param TEventParameter event parameter to be passed to the event handlers
+ */
+ protected function onPreRender($param)
+ {
if($this->getEnabled(true))
- $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');
+ {
+ $scripts = $this->getPage()->getClientScript();
+ $options = $this->getPostBackOptions();
+ $postback = $scripts->getPostBackEventReference($this, '', $options, false);
+ $code = "{$postback}; Event.stop(e);";
+ $scripts->registerClientEvent($this, "click", $code);
+ }
+ parent::onPreRender($param);
}
/**
@@ -102,8 +120,11 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
protected function getPostBackOptions()
{
$flag=false;
- $options=new TPostBackOptions();
- if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0)
+
+ $option=new TPostBackOptions();
+ $group = $this->getValidationGroup();
+ $hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
+ if($this->getCausesValidation() && $hasValidators)
{
$flag=true;
$options->setPerformValidation(true);
@@ -183,22 +204,6 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
}
/**
- * @return string the javascript to be executed when the button is clicked
- */
- public function getOnClientClick()
- {
- return $this->getViewState('OnClientClick','');
- }
-
- /**
- * @param string the javascript to be executed when the button is clicked. Do not prefix it with "javascript:".
- */
- public function setOnClientClick($value)
- {
- $this->setViewState('OnClientClick',$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()