summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-06-21 00:26:42 +0000
committerxue <>2006-06-21 00:26:42 +0000
commitc72abec23e8b4255fcaaaa0fbede3341d0149ee8 (patch)
tree9264ed238ae3184a617b8d47aa0eb3c8d7362697
parente1fdc054f90b8478e7c5b942263e66db3a35dca1 (diff)
Fixed #231.
-rw-r--r--HISTORY2
-rw-r--r--demos/quickstart/protected/pages/Controls/Button.page2
-rw-r--r--framework/Web/UI/WebControls/TButton.php71
-rw-r--r--framework/Web/UI/WebControls/THyperLink.php2
4 files changed, 51 insertions, 26 deletions
diff --git a/HISTORY b/HISTORY
index 784ce572..3489fc71 100644
--- a/HISTORY
+++ b/HISTORY
@@ -9,7 +9,9 @@ CHG: ensureChildControls() is now invoked in TControl::initRecursive (Qiang)
CHG: Postback enabled control will always disable default client-side browser action. (Qiang)
CHG: CSS and JS files in a theme are now included in page in alphabetic order (Qiang)
ENH: Ticket#206 - Added OnValidate, OnError, OnSuccess events to validators (Qiang)
+ENH: Ticket#231 - Added TButton.ButtonType property to allow reset button (Qiang)
ENH: Ticket#232 - Allow <%# %> and <%= %> embedded within property values (Qiang)
+
ENH: TRepeater, TDataList and TDataGrid will store data indices in DataKeys if DataKeyField is not set. (Qiang)
ENH: Added TPageService.BasePageClass property (Qiang)
diff --git a/demos/quickstart/protected/pages/Controls/Button.page b/demos/quickstart/protected/pages/Controls/Button.page
index 5c827725..37b90062 100644
--- a/demos/quickstart/protected/pages/Controls/Button.page
+++ b/demos/quickstart/protected/pages/Controls/Button.page
@@ -4,7 +4,7 @@
<com:DocLink ClassPath="System.Web.UI.WebControls.TButton" />
<p>
-<tt>TButton</tt> creates a click button on a Web page. The button's caption is specified by <tt>Text</tt> property. A button is used to submit data to a page. <tt>TButton</tt> raises two server-side events, <tt>Click</tt> and <tt>Command</tt>, when it is clicked on the client-side. The difference between <tt>Click</tt> and <tt>Command</tt> events is that the latter event is bubbled up to the button's ancestor controls. A <tt>Command</tt> event handler can use <tt>CommandName</tt> and <tt>CommandParameter</tt> associated with the event to perform specific actions.
+<tt>TButton</tt> creates a click button on a Web page. The button's caption is specified by <tt>Text</tt> property. A button is used to submit data to a page. <tt>TButton</tt> raises two server-side events, <tt>OnClick</tt> and <tt>OnCommand</tt>, when it is clicked on the client-side. The difference between <tt>OnClick</tt> and <tt>OnCommand</tt> events is that the latter event is bubbled up to the button's ancestor controls. An <tt>OnCommand</tt> event handler can use <tt>CommandName</tt> and <tt>CommandParameter</tt> associated with the event to perform specific actions.
</p>
<p>
Clicking on button can trigger form validation, if <tt>CausesValidation</tt> is true. And the validation may be restricted within a certain group of validator controls according to <tt>ValidationGroup</tt>.
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index a233e717..d24f5ef4 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -13,37 +13,35 @@
/**
* TButton class
*
- * TButton creates a click button on the page. It is used to submit data to a page.
- * You can create either a <b>submit</b> button or a <b>command</b> button.
+ * TButton creates a click button on the page. It is mainly used to submit data to a page.
*
- * A <b>command</b> 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 TButton
+ * TButton raises two server-side events, {@link onClick OnClick} and {@link onCommand OnCommand},
+ * when it is clicked on the client-side. The difference between these two events
+ * is that the event {@link onCommand OnCommand} is bubbled up to the button's ancestor controls.
+ * And within the event parameter for {@link onCommand OnCommand} contains the reference
+ * to the {@link setCommandName CommandName} and {@link setCommandParameter CommandParameter}
+ * property values that are set for the button object. This allows you to create multiple TButton
* components on a Web page and programmatically determine which one is clicked
- * with what parameter. You can provide an event handler for
- * {@link onCommand OnCommand} 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}.
+ * with what parameter.
*
- * A <b>submit</b> 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 TButton component is a submit button.
- * You can provide an event handler for the {@link onClick OnClick} event
- * to programmatically control the actions performed when the submit button is clicked.
- *
- * Clicking on button can trigger form validation, if
+ * Clicking on button can also trigger form validation, if
* {@link setCausesValidation CausesValidation} is true.
- * And the validation may be restricted within a certain group of validator
+ * The validation may be restricted within a certain group of validator
* controls by setting {@link setValidationGroup ValidationGroup} property.
* If validation is successful, the data will be post back to the same page.
*
* TButton displays the {@link setText Text} property as the button caption.
*
+ * TButton can be one of three {@link setButtonType ButtonType}: Submit, Button and Reset.
+ * By default, it is a Submit button and the form submission uses the browser's
+ * default submission capability. If it is Button or Reset, postback may occur
+ * if one of the following conditions is met:
+ * - an event handler is attached to {@link onClick OnClick} event;
+ * - an event handler is attached to {@link onCommand OnCommand} event;
+ * - the button is in a non-empty validation group.
+ * In addition, clicking on a Reset button will clear up all input fields
+ * if the button does not cause a postback.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
@@ -68,13 +66,13 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr
{
$page=$this->getPage();
$page->ensureRenderInForm($this);
- $writer->addAttribute('type','submit');
+ $writer->addAttribute('type',strtolower($this->getButtonType()));
if(($uniqueID=$this->getUniqueID())!=='')
$writer->addAttribute('name',$uniqueID);
$writer->addAttribute('value',$this->getText());
if($this->getEnabled(true))
{
- if($this->canCauseValidation())
+ if($this->needPostBackScript())
{
$writer->addAttribute('id',$this->getClientID());
$this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TButton',$this->getPostBackOptions());
@@ -101,6 +99,15 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr
}
/**
+ * @return boolean whether the button needs javascript to do postback
+ */
+ protected function needPostBackScript()
+ {
+ return $this->canCauseValidation() || ($this->getButtonType()!=='Submit' &&
+ ($this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand')));
+ }
+
+ /**
* Returns postback specifications for the button.
* This method is used by framework and control developers.
* @return array parameters about how the button defines its postback behavior.
@@ -245,6 +252,22 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr
{
$this->setViewState('ValidationGroup',$value,'');
}
+
+ /**
+ * @return string the type of the button. Defaults to 'Submit'.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType','Submit');
+ }
+
+ /**
+ * @param string the type of the button. Valid values include 'Submit', 'Reset', 'Button'.
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'Submit','Reset','Button'),'Submit');
+ }
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/THyperLink.php b/framework/Web/UI/WebControls/THyperLink.php
index 5489727c..011ce4db 100644
--- a/framework/Web/UI/WebControls/THyperLink.php
+++ b/framework/Web/UI/WebControls/THyperLink.php
@@ -73,7 +73,7 @@ class THyperLink extends TWebControl
if(($toolTip=$this->getToolTip())!=='')
$image->setToolTip($toolTip);
if(($text=$this->getText())!=='')
- $image->setAlternateText(THttpUtility::htmlEncode($text));
+ $image->setAlternateText($text);
$image->renderControl($writer);
}
}