C# 父子页面传值
业务需求是:父页面点击“选择任务”按钮进入任务列表页。(项目进度周报)
父页面如下:
任务列表页:
选择某一个任务,点击“确定”后返回父页面所需数据。
父页面“选择任务” 按钮触发事件。
/// <summary> /// 选择任务按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSelectTask_Click(object sender, EventArgs e) { string GantId = Request.QueryString["gantid"]; string gantTaskIds = Request.QueryString["gantTaskIds"]; string urlParams = string.Format("?GantId={0}&gantTaskIds={1}", GantId, gantTaskIds); string openUrl = "SelectTask.aspx" + urlParams; //打开选择任务页面 PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hfNewTaskID.ClientID, hfNewTaskUID.ClientID,lblTaskName.ClientID, lblPlanInfo.ClientID, lblProgressNow.ClientID, hfProgressNow.ClientID) + Window1.GetShowReference(openUrl)); }
任务列表页面,确定按钮事件:
//确定按钮 protected void btnConfirm_Click(object sender, EventArgs e) { var firstRowDataKeys = GridUtil.GetFirstSelected(Grid1, 6); if (firstRowDataKeys == null) { Alert.Show("请选择一项!", MessageBoxIcon.Warning); } else { //Id,UID,ProjectId,Name,days string id = firstRowDataKeys[0]; string uid = firstRowDataKeys[1]; string name= firstRowDataKeys[3]; string days = firstRowDataKeys[4]; string planInfo= firstRowDataKeys[5]; //选定以后查询本任务对应的最新进度 string gantId = Request.QueryString["gantid"]; if (!string.IsNullOrWhiteSpace(id)&& !string.IsNullOrWhiteSpace(uid) && !string.IsNullOrWhiteSpace(gantId)) { string progressNow = pwtBll.GetTaskProgressNow(gantId, uid, id); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(id, uid, name, planInfo, progressNow, progressNow) + ActiveWindow.GetHideReference()); } } }
斩后知