This blog is a knowledge base...where I clip cool tricks and urls

Script#

Writing javascript in C#
clipped from www.nikhilk.net
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;
}
}
 blog it

No comments: