public void fileUploaded( object sender, EventArgs ea ) { string name = fu.File.FileName; log.Debug("fileUploaded. ", fu.File, fu.File.FileName, fu.File.ContentType ); Regex imageType = new Regex("image/(png|jpg|jpe|pjpeg|x-png|jpeg|gif)",RegexOptions.Compiled ); if( imageType.IsMatch( fu.File.ContentType ) ) { if (SaveToLocalStorage) { savePath = saveFormat.Replace("$FileName", name); savePath = savePath.Replace("$Extension", name.Substring(name.LastIndexOf('.') + 1)); physicalPath = RootContext.HttpContext.Server.MapPath(savePath); fu.File.SaveAs(physicalPath); img.Url = savePath + "?" + (uid ?? Util.ConvertToBase32(DateTime.UtcNow.Ticks)); } else { HttpPostedFile = fu.File; } unsetButton.Visible = true; img.Visible = true; if( OnImageUploaded != null ) OnImageUploaded( this, null ); if( errorLabel != null ) errorLabel.Visible = false; } else { log.Debug("image upload failed for content type ", fu.File.ContentType ); if( errorLabel == null ) { errorLabel = RootContext.CreateWidget<Label>(this); errorLabel.Text = "File is not a valid image type. Image format must be one of: png, jpg or gif."; errorLabel.ClassName = "error"; } else errorLabel.Visible = true; } FileUpload newFu = RootContext.CreateWidget<FileUpload>(); fu.Replace(newFu); fu = newFu; fu.OnFileUploaded += new EventHandler(fileUploaded); }
public void SetupStandardLogin() { this.usernameField = this.RootContext.CreateWidget<LabeledWidget<TextBox>>(this); this.usernameField.Widget.Id = "username"; this.usernameField.LabelText = "User Name:"; this.usernameField.AppendClass("username"); this.usernameField.Widget.OnEnter += delegate { login(); }; this.usernameField.Widget.SetClientAttribute("name","'username'"); this.usernameField.Widget.Focus(); this.passwordField = this.RootContext.CreateWidget<LabeledWidget<TextBox>>(this); this.passwordField.Widget.Id = "password"; this.passwordField.LabelText = "Password:"******"name","'password'"); this.passwordField.AppendClass("password"); this.errorText = this.RootContext.CreateWidget<Label>(this); this.errorText.ClassName = "error"; this.errorText.Visible = false; Button submitBtn = this.RootContext.CreateWidget<Button>(this); submitBtn.Label = "Login"; submitBtn.OnClick += delegate { login(); }; if( showCancel ) { Button cancelBtn = this.RootContext.CreateWidget<Button>(this); cancelBtn.Label = "Cancel"; cancelBtn.OnClick += new EventHandler<ClickEventArgs>(cancelBtn_OnClick); } }