public class HelloWorldScriptlet : IScriptlet { private Button _okButton; private TextBox _nameTextBox; private Label _helloLabel; private XMLHttpRequest _request; public void Start() { _okButton = new Button(Document.GetElementById("okButton")); _nameTextBox = new TextBox(Document.GetElementById("nameTextBox")); _helloLabel = new Label(Document.GetElementById("helloLabel")); _okButton.Click += new EventHandler(OnOKButtonClick); } private void OnOKButtonClick(object sender, EventArgs e) { Callback completedCallback = new Callback(this.OnRequestComplete); _request = new XMLHttpRequest(); _request.Onreadystatechange = Delegate.Unwrap(completedCallback); _request.Open("GET", "Hello.axd?name=" + _nameTextBox.Text, /* async */ true); _request.Send(null); } private void OnRequestComplete() { if (_request.ReadyState == 4) { _request.Onreadystatechange = null; string greeting = _request.ResponseText; _helloLabel.Text = greeting; } } |
No comments:
Post a Comment