public static void addStyleSheet(string css, string key, Page currentPage, WebControl control) { ControlCollection ctrls = currentPage.Controls; if (currentPage.Master != null) ctrls = currentPage.Master.Controls; foreach (Control ctrl in ctrls) { if (ctrl.GetType().Name == "HtmlHead") { ctrls = ctrl.Controls; break; } } if (key != null) { foreach (Control ctrl in ctrls) { if (ctrl.ID == key) return; } } string url = currentPage.ClientScript.GetWebResourceUrl(control.GetType(), "ESWCtrls.ResEmbed.Styles." + css); HtmlLink link = new HtmlLink(); link.Attributes.Add("type", "text/css"); link.Attributes.Add("rel", "stylesheet"); link.Attributes.Add("media", "screen"); link.Href = url; link.ID = key; ctrls.Add(new LiteralControl("\n")); ctrls.Add(link); }
public void RegisterFromResource(WebControl control, Type resourceType, string resourceNamePrefix, string resourceName) { var scriptManager = GetPageScriptManager(control); if (ResourceAddedAlready(scriptManager, resourceName)) return; var cssUrl = control.Page.ClientScript.GetWebResourceUrl(resourceType, resourceNamePrefix + "." + resourceName); var css = @"<link href=""" + cssUrl + @""" type=""text/css"" rel=""stylesheet"" />"; ScriptManager.RegisterClientScriptBlock(control.Page, control.GetType(), resourceName, css, false); }
/// <summary> /// Configures a control to display and toggle following for the specified entity /// </summary> /// <param name="followEntity">The follow entity. NOTE: Make sure to use PersonAlias instead of Person when following a Person</param> /// <param name="followControl">The follow control.</param> /// <param name="follower">The follower.</param> public static void SetFollowing( IEntity followEntity, WebControl followControl, Person follower ) { var followingEntityType = EntityTypeCache.Read( followEntity.GetType() ); if ( follower != null && follower.PrimaryAliasId.HasValue ) { using ( var rockContext = new RockContext() ) { var personAliasService = new PersonAliasService( rockContext ); var followingService = new FollowingService( rockContext ); var followingQry = followingService.Queryable() .Where( f => f.EntityTypeId == followingEntityType.Id && f.PersonAlias.PersonId == follower.Id ); followingQry = followingQry.Where( f => f.EntityId == followEntity.Id ); if ( followingQry.Any() ) { followControl.AddCssClass( "following" ); } else { followControl.RemoveCssClass( "following" ); } } int entityId = followEntity.Id; // only show the following control if the entity has been saved to the database followControl.Visible = entityId > 0; string script = string.Format( @"Rock.controls.followingsToggler.initialize($('#{0}'), {1}, {2}, {3}, {4});", followControl.ClientID, followingEntityType.Id, entityId, follower.Id, follower.PrimaryAliasId ); ScriptManager.RegisterStartupScript( followControl, followControl.GetType(), "following", script, true ); } }
internal List<string> RenderGVIEvents(WebControl PageControl) { List<string> eventsList = new List<string>(); System.Reflection.PropertyInfo[] props = PageControl.GetType().GetProperties(); foreach (System.Reflection.PropertyInfo prop in props) { GviEventOption option = prop.GetCustomAttributes(typeof(GviEventOption), false) .Cast<GviEventOption>().FirstOrDefault(); if (option == null) continue; object value = prop.GetValue(PageControl,null); if ((value == null) || (string.IsNullOrEmpty(value.ToString()))) continue; string foo = string.Format("google.visualization.events.addListener(chart, '{0}', chart.{1} = function(){{ {1}(chart); }});", option.EventName, value); foo = foo.Replace(";;", ";"); eventsList.Add(foo); } return eventsList; }
/// <summary> /// 取得Control对应的xml /// </summary> /// <param name="control">Control</param> /// <param name="prop">绑定Control的属性</param> /// <param name="field">绑定的字段</param> /// <param name="format">绑定的格式</param> /// <returns>xml</returns> private string GetControlXml(WebControl control, PropertyInfo prop, string field, string format) { StringBuilder builder = new StringBuilder(); //builder.Append("<br/>"); if (control != null) { StringBuilder builderInnerHtml = new StringBuilder(); Type controltype = control.GetType(); //if (controltype.Namespace == "Srvtools") //{ // builder.Append(string.Format("<{0}:{1} ID=\"{2}\" runat=\"server\" ", INFOLIGHTMARK, controltype.Name, control.ID)); //} //else //{ // builder.Append(string.Format("<{0}:{1} ID=\"{2}\" runat=\"server\" ", "Asp", controltype.Name, control.ID)); //} if (controltype.Namespace == "Srvtools") { builder.Append(string.Format("<{0}:{1} runat=\"server\" ", INFOLIGHTMARK, controltype.Name)); } else { builder.Append(string.Format("<{0}:{1} runat=\"server\" ", "JQTools", controltype.Name)); } if (prop != null) { builder.Append(string.Format("{0}='<%# Bind(\"{1}\"", prop.Name, field, format)); if (!string.IsNullOrEmpty(format)) { builder.Append(string.Format("{0}", format)); } builder.Append(") %>' "); } //PropertyInfo[] infos = controltype.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); PropertyInfo[] infos = controltype.GetProperties(); List<String> listTemp = new List<string>(); for (int i = 0; i < infos.Length; i++) { if (infos[i].Name == "ValidateRequestMode") continue; if (prop == null || (prop != null && prop.Name != infos[i].Name)) { if (listTemp.Contains(infos[i].Name)) continue; listTemp.Add(infos[i].Name); if (!IsVisibilityHidden(infos[i])) { if (infos[i].PropertyType == typeof(string) || infos[i].PropertyType == typeof(int) || infos[i].PropertyType == typeof(bool) || infos[i].PropertyType.BaseType == typeof(Enum)) { object value = infos[i].GetValue(control, null); object defaultvalue = GetDefaultValue(infos[i]); if (infos[i].CanWrite && value != null && !String.IsNullOrEmpty(value.ToString()) && value != defaultvalue && infos[i].Name != "Visible") { builder.Append(string.Format("{0}=\"{1}\" ", infos[i].Name, value)); } } else if (infos[i].PropertyType.Name == "JQCollection`1") { string collectionxml = GetCollectionXml(infos[i], (IJQProperty)infos[i].GetValue(control, null)); if (collectionxml.Length > 0) { builderInnerHtml.AppendLine(collectionxml); } } } } } builder.AppendLine(">"); builder.Append(builderInnerHtml.ToString()); if (controltype.Namespace == "Srvtools") { builder.AppendLine(string.Format("</{0}:{1}>", INFOLIGHTMARK, controltype.Name)); } else { builder.AppendLine(string.Format("</{0}:{1}>", "JQTools", controltype.Name)); } } return builder.ToString(); }
/// <summary> /// PopulateDepartment by WebControl /// </summary> public static void InitializeDepartments(WebControl control, SqlDataSource DepartmentDataSource=null) { object Departments = null; if (DepartmentDataSource != null) { Departments = DepartmentDataSource; } else { Departments = DepartmentManager.Departments(); } switch(control.GetType().Name) { case "DropDownList": DropDownList DDList = (DropDownList)control; DDList.Items.Clear(); DDList.DataSource = Departments; DDList.DataTextField = "DepartmentName"; DDList.DataValueField = "Id"; DDList.DataBind(); break; case "GridView": GridView gvDepartments = (GridView)control; gvDepartments.DataSource = Departments; gvDepartments.DataBind(); break; case "ListBox": ListBox ListBoxDepartments = (ListBox)control; ListBoxDepartments.DataSource = Departments; ListBoxDepartments.DataTextField = "DepartmentName"; ListBoxDepartments.DataValueField = "Id"; ListBoxDepartments.DataBind(); break; case "CheckBoxList": CheckBoxList chkBoxListDepartment = (CheckBoxList)control; chkBoxListDepartment.DataSource = Departments; chkBoxListDepartment.DataTextField = "DepartmentName"; chkBoxListDepartment.DataValueField = "Id"; chkBoxListDepartment.DataBind(); break; } }
/// <summary> /// Common Tests of WebControl. /// </summary> protected void GHTTestCommon_WebControl(WebControl obj, string MemberName) { WebControl objNew; bool bExceptionCaught = false; MemberName = MemberName.ToLower(); //AccessKey if (MemberName.CompareTo("AccessKey".ToLower())== 0) { //Press Alt-Y to get focus here obj.AccessKey = ""; //empty is ok obj.AccessKey = "Y"; objNew = (WebControl)GHTElementClone(obj.GetType()); // test Exceptions try { objNew.AccessKey = "XX"; GHTActiveSubTest.Controls.Add(objNew); } catch (ArgumentException) { bExceptionCaught = true; } if (bExceptionCaught == true) { GHTSubTestAddResult(GHTActiveSubTest, MemberName + " ArgumentException OK"); } bExceptionCaught = false; } //Attributes tested at System.Web.UI.AttributeCollection //BackColor if (MemberName.CompareTo("BackColor".ToLower())== 0) { obj.BackColor = System.Drawing.Color.AliceBlue; objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.BackColor = System.Drawing.Color.Magenta; GHTActiveSubTest.Controls.Add(objNew); } //BorderColor if (MemberName.CompareTo("BorderColor".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.BorderColor = System.Drawing.Color.AliceBlue; GHTActiveSubTest.Controls.Add(objNew); } //BorderStyle if (MemberName.CompareTo("BorderStyle".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.BorderStyle = System.Web.UI.WebControls.BorderStyle.Dotted; GHTActiveSubTest.Controls.Add(objNew); } //BorderWidth if (MemberName.CompareTo("BorderWidth".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.BorderWidth = 10; GHTActiveSubTest.Controls.Add(objNew); } // ControlStyle // ControlStyleCreated //CssClass if (MemberName.CompareTo("CssClass".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.CssClass = "zoobie"; GHTActiveSubTest.Controls.Add(objNew); } //Enabled if (MemberName.CompareTo("Enabled".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.Enabled = true; GHTActiveSubTest.Controls.Add(objNew); } //Font if (MemberName.CompareTo("Font".ToLower())== 0) { GHTSubTestAddResult(GHTActiveSubTest, MemberName + " " + obj.Font.ToString()); } //ForeColor if (MemberName.CompareTo("ForeColor".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.ForeColor = System.Drawing.Color.Cornsilk; GHTActiveSubTest.Controls.Add(objNew); } //Height if (MemberName.CompareTo("Height".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.Height = 30; GHTActiveSubTest.Controls.Add(objNew); } //Style if (MemberName.CompareTo("Style".ToLower())== 0) { GHTSubTestAddResult(GHTActiveSubTest, MemberName + " " + obj.Style.ToString()); } // if (MemberName.CompareTo("TagKey".ToLower())== 0) // { // obj.TagKey = "TagKey"; // } // if (MemberName.CompareTo("TagName".ToLower())== 0) // { // obj.TagName = "TagName"; // } //TabIndex if (MemberName.CompareTo("TabIndex".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.TabIndex = 2; GHTActiveSubTest.Controls.Add(objNew); } //ToolTip if (MemberName.CompareTo("ToolTip".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.ToolTip = "ToolTip"; GHTActiveSubTest.Controls.Add(objNew); } //Width if (MemberName.CompareTo("Width".ToLower())== 0) { objNew = (WebControl)GHTElementClone(obj.GetType()); objNew.Width = 60; GHTActiveSubTest.Controls.Add(objNew); } }
private string GetControlXml(WebControl control, PropertyInfo prop, string field, string format) { StringBuilder builder = new StringBuilder(); if (control != null) { StringBuilder builderInnerHtml = new StringBuilder(); Type controltype = control.GetType(); if (controltype.Namespace == "Srvtools") { builder.Append(string.Format("<{0}:{1} ID=\"{2}\" runat=\"server\" ", INFOLIGHTMARK, controltype.Name, control.ID)); } else { builder.Append(string.Format("<{0}:{1} ID=\"{2}\" runat=\"server\" ", "Asp", controltype.Name, control.ID)); } if (prop != null) { builder.Append(string.Format("{0}='<%# Bind(\"{1}\"", prop.Name, field)); if (!string.IsNullOrEmpty(format)) { builder.Append(string.Format("{0}", FormatEditMask(format))); } builder.Append(") %>' "); } PropertyInfo[] infos = controltype.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); for (int i = 0; i < infos.Length; i++) { if (prop == null || (prop != null && prop.Name != infos[i].Name)) { if (!IsVisibilityHidden(infos[i])) { if (infos[i].PropertyType == typeof(string) || infos[i].PropertyType == typeof(int) || infos[i].PropertyType == typeof(bool) || infos[i].PropertyType.BaseType == typeof(Enum)) { object value = infos[i].GetValue(control, null); object defaultvalue = GetDefaultValue(infos[i]); if (infos[i].CanWrite && value != defaultvalue) { builder.Append(string.Format("{0}=\"{1}\" ", infos[i].Name, value)); } } else if (infos[i].PropertyType.BaseType == typeof(InfoOwnerCollection)) { string collectionxml = GetCollectionXml(infos[i], (InfoOwnerCollection)infos[i].GetValue(control, null)); if (collectionxml.Length > 0) { builderInnerHtml.AppendLine(collectionxml); } } } } } builder.AppendLine(">"); builder.Append(builderInnerHtml.ToString()); if (controltype.Namespace == "Srvtools") { builder.AppendLine(string.Format("</{0}:{1}>", INFOLIGHTMARK, controltype.Name)); } else { builder.AppendLine(string.Format("</{0}:{1}>", "Asp", controltype.Name)); } } return builder.ToString(); }
private static string GetControlValue(WebControl ctrl) { RadInputControl txt = ctrl as RadInputControl; if (null != txt) return txt.Text; throw new NotSupportedException(ctrl.GetType().Name); }