protected void gvClubs_RowDataBound(object sender, GridViewRowEventArgs e) { if (e != null && e.Row.RowType == DataControlRowType.DataRow) { Controls_ClubControls_ViewClub vc = (Controls_ClubControls_ViewClub)e.Row.FindControl("viewClub1"); vc.ActiveClub = (Club)e.Row.DataItem; } }
public static string PopulateClub(int idClub) { StringBuilder sb = new StringBuilder(); try { // We have no Page, so things like Page_Load don't get called. // We fix this by faking a page and calling Server.Execute on it. This sets up the form and - more importantly - causes Page_load to be called on loaded controls. using (Page p = new FormlessPage()) { p.Controls.Add(new HtmlForm()); using (StringWriter sw1 = new StringWriter(CultureInfo.InvariantCulture)) HttpContext.Current.Server.Execute(p, sw1, false); HttpRequest r = HttpContext.Current.Request; if (!r.IsLocal && !r.UrlReferrer.Host.EndsWith(Branding.CurrentBrand.HostName, StringComparison.OrdinalIgnoreCase)) { throw new MyFlightbookException("Unauthorized attempt to populate club! {0}, {1}"); } Club c = Club.ClubWithID(idClub); if (c == null) { return(string.Empty); } Controls_ClubControls_ViewClub vc = (Controls_ClubControls_ViewClub)p.LoadControl("~/Controls/ClubControls/ViewClub.ascx"); vc.LinkToDetails = true; vc.ActiveClub = c; p.Form.Controls.Add(vc); // Now, write it out. StringWriter sw = null; try { sw = new StringWriter(sb, CultureInfo.InvariantCulture); using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw)) { sw = null; vc.RenderControl(htmlTW); } } finally { if (sw != null) { sw.Dispose(); } } } } catch (MyFlightbookException ex) { sb.Append(ex.Message); } return(sb.ToString()); }