呵呵,搞了半天就是要一句权威的这句话:
If the user clicks the Submit button to submit the form, and that button has a name attribute specified, that button contributes a name/value pair to the submitted data.
If the user clicks the Submit button to submit the form, and that button has a name attribute specified, that button contributes a name/value pair to the submitted data.
[C#]
using System;
using System.Web;
using System.Web.UI;
using System.Collections.Specialized;
namespace CustomControls{
public class MyTextBox: Control, IPostBackDataHandler {
public String Text {
get {
return (String) ViewState["Text"];
}
set {
ViewState["Text"] = value;
}
}
public event EventHandler TextChanged;
public virtual bool LoadPostData(string postDataKey,
NameValueCollection values) {
String presentValue = Text;
String postedValue = values[postDataKey];
if (!presentValue.Equals(postedValue)){
Text = postedValue;
return true;
}
return false;
}
public virtual void RaisePostDataChangedEvent() {
OnTextChanged(EventArgs.Empty);
}
<form method="POST" action="MyTextBox.aspx" runat=server>
The text box below is an instance of a custom text box.<br>
It raises a text changed event when the text in the text box changes.<br><br>
Enter your name: <Custom:MyTextBox Text=" " OnTextChanged = "Text_Changed" id = "Box" runat=server/>
<br><br>
<asp:Button Text = "Submit" runat = server/>
</form>
</body>
</html>