protected void SaveBtn_Click(object sender, EventArgs e) { _groupRepo = RepositoryFactory.CreateGroupRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <GroupViewModel>(this.Page); var validator = new Validator(); var validResult = validator.ValidateModel(model); if (!validResult.IsValid) { Response.Write(validResult.ErrorMessage.ToString().ToAlertFormat()); return; } //btn處理 ViewUtils.ButtonOff(SaveBtn, CoverBtn); //存檔 var responseMessage = ""; var successRdUrl = String.Empty; try { if (String.IsNullOrWhiteSpace(Request["GroupType"])) { _groupRepo.CreateData(model); successRdUrl = @"GroupDataList.aspx?orderField=CreateDate&descending=True"; responseMessage = "新增成功!"; } else { _groupRepo.EditData(model); successRdUrl = @"GroupDataList.aspx?orderField=ModifyDate&descending=True"; responseMessage = "編輯成功!"; } //btn處理 ViewUtils.ButtonOn(SaveBtn, CoverBtn); responseMessage = responseMessage.ToAlertAndRedirect(successRdUrl); } catch (Exception ex) { responseMessage = String.Concat("存檔失敗!\r\n錯誤訊息: ", ex.Message).ToAlertFormat(); ViewUtils.ShowRefreshBtn(CoverBtn, RefreshBtn); } finally { Response.Write(responseMessage); } }