protected override void OnInit(EventArgs e) { base.OnInit(e); Control oControl = new System.Web.UI.UserControl().LoadControl(_usercontrolPath); if (HasSettings(oControl.GetType())) { DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); List <Setting <string, string> > s = ss.GetSettings(((umbraco.cms.businesslogic.datatype.DefaultData)_data).DataTypeDefinitionId); ss.Dispose(); foreach (Setting <string, string> setting in s) { try { if (!string.IsNullOrEmpty(setting.Key)) { oControl.GetType().InvokeMember(setting.Key, System.Reflection.BindingFlags.SetProperty, null, oControl, new object[] { setting.Value }); } } catch (MissingMethodException) { } } } this.Controls.Add(oControl); if (!Page.IsPostBack) { ((IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor).value = _data.Value; } }
protected void Page_Load(object sender, EventArgs e) { iconIBN.Href = Page.ResolveUrl("~/portal.ico"); RegisterScripts(); Response.Cache.SetNoStore(); if (controlName != "") { frmMain.Enctype = this.enctype; System.Web.UI.UserControl control = (System.Web.UI.UserControl)LoadControl(controlName); foreach (DictionaryEntry de in controlProperties) { control.GetType().BaseType.GetProperty(de.Key.ToString()).SetValue(control, de.Value, null); } try { phMain.Controls.Add(control); } catch (HttpException) { } } }
private UserControl LoadUC(string LoadUCName, params object[] constructorParameters) { System.Web.UI.UserControl userControl = null; string ucControlPath = string.Empty; ucControlPath = LoadUCName; List <Type> constParamTypes = new List <Type>(); foreach (object constParam in constructorParameters) { constParamTypes.Add(constParam.GetType()); } if (!string.IsNullOrEmpty(ucControlPath)) { userControl = (UserControl)this.Page.LoadControl(ucControlPath); } ConstructorInfo constructor = userControl.GetType().BaseType.GetConstructor(constParamTypes.ToArray()); //And then call the relevant constructor if (constructor == null) { throw new MemberAccessException("The requested constructor was not found on : " + userControl.GetType().BaseType.ToString()); } else { constructor.Invoke(userControl, constructorParameters); } return(userControl); }
protected void Page_Load(object sender, System.EventArgs e) { iconIBN.Href = Page.ResolveUrl("~/portal.ico"); RegisterScripts(); tableContactUs.Visible = GlobalResourceManager.Options["TableContactUsVisible"]; tableFeedback.Visible = GlobalResourceManager.Options["TableFeedbackVisible"]; lblProductName.Text = IbnConst.ProductFamily; // Default Settings printScript.Visible = false; frmMain.Visible = true; body.Attributes.Add("onload", "javascript:ScrollIt()"); //body.Attributes.Add("onscroll", "javascript:setcoords()"); frmMain.Enctype = this.enctype; if (controlName != "") { System.Web.UI.UserControl control = (System.Web.UI.UserControl)LoadControl(controlName); if (ControlProperty != null && ControlPropertyValue != null) { control.GetType().BaseType.GetProperty(ControlProperty).SetValue(control, ControlPropertyValue, null); } phMain.Controls.Add(control); if (control is IPageTemplateTitle) { this.Title = ((IPageTemplateTitle)control).Modify(this.Title); } } BindData(); }
public void RegisterInitializationScripts(UserControl control, params string[] scripts) { var key = control.GetType().BaseType.Name; if (_initializationLines.ContainsKey(key)) return; _initializationLines.Add(key, scripts.ToSeparatedString("\r\n")); }
public static bool AlertRedirectWindowForAscx(System.Web.UI.UserControl ascxPage, string strMessage, string RedirectPage) { string strScript = @"alert( '" + strMessage + "' ); window.location.href='" + RedirectPage + "';"; System.Web.UI.ScriptManager.RegisterClientScriptBlock(ascxPage, ascxPage.GetType(), "Key1", strScript, true); return(false); }
public static bool CreateMessageAlertForAscxPage(System.Web.UI.UserControl ascxPage, string strMessage) { { string strScript = "alert( \"" + strMessage + "\" )"; System.Web.UI.ScriptManager.RegisterClientScriptBlock(ascxPage, ascxPage.GetType(), "Key1", strScript, true); return(false); } return(true); }
/// <summary> /// Registers a script near the end of the form only allowed to register Js scripts. /// </summary> /// <param name="control">The control.</param> /// <param name="scriptName">Name of the script.</param> /// <param name="script">The script.</param> /// <param name="minimized">if set to <c>true</c> [minimized].</param> public void RegisterStartUpScript(UserControl control, string scriptName, string script, bool minimized = false) { Contract.Requires(control != null); if (minimized) { script = this.MinimizeJsCode(script); } control.Page.ClientScript.RegisterStartupScript(control.GetType(), scriptName, string.Format("<script>{0}</script>", script)); }
protected override void OnInit(EventArgs e) { base.OnInit (e); Control oControl = new System.Web.UI.UserControl().LoadControl(_usercontrolPath); if (HasSettings(oControl.GetType())) { DataEditorSettingsStorage ss = new DataEditorSettingsStorage(); List<Setting<string, string>> s = ss.GetSettings(((umbraco.cms.businesslogic.datatype.DefaultData)_data).DataTypeDefinitionId); ss.Dispose(); foreach (Setting<string, string> setting in s) { try { if(!string.IsNullOrEmpty(setting.Key)) { oControl.GetType().InvokeMember(setting.Key, System.Reflection.BindingFlags.SetProperty, null, oControl, new object[] { setting.Value }); } } catch (MissingMethodException) { } } } // Add property data to the usercontrol if it supports it // TODO: Find the best way to test for an interface! IUsercontrolPropertyData propertyData = oControl as IUsercontrolPropertyData; if (propertyData != null) { propertyData.PropertyObject = new Property(((usercontrolData)_data).PropertyId); } this.Controls.Add(oControl); if (!Page.IsPostBack) ((IUsercontrolDataEditor)Controls[0] as IUsercontrolDataEditor).value = _data.Value; }
public static void SetPropertyValues(UserControl control, HttpContext context) { var metadata = GetMetadata(control.GetType()); foreach (var property in metadata.Keys) { object value = GetValue(metadata[property], context) ?? GetDefaultValue(property); if (value != null) { property.SetValue(control, Convert.ChangeType(value, property.PropertyType), null); } } }
protected void Page_Load(object sender, System.EventArgs e) { iconIBN.Href = Page.ResolveUrl("~/portal.ico"); RegisterScripts(); LocRM = new ResourceManager("Mediachase.UI.Web.App_GlobalResources.Modules.Resources.strTemplate", typeof(PageTemplateExternal).Assembly); tableContactUs.Visible = GlobalResourceManager.Options["TableContactUsVisible"]; lblProductName.Text = IbnConst.ProductFamily; if (Thread.CurrentThread.CurrentUICulture.DateTimeFormat.PMDesignator == String.Empty) { Is24Hours = "1"; } //Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), // "var Is24Hours = true;", true); int offset = User.GetCurrentBias(); TimeOffset = offset.ToString(); //Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), // "var TimeOffset = " + offset + ";", true); // Default Settings printScript.Visible = false; frmMain.Visible = true; body.Attributes.Add("onload", "javascript:ScrollIt()"); body.Attributes.Add("onscroll", "javascript:setcoords()"); frmMain.Enctype = this.enctype; if (controlName != "") { System.Web.UI.UserControl control = (System.Web.UI.UserControl)LoadControl(controlName); if (ControlProperty != null && ControlPropertyValue != null) { control.GetType().BaseType.GetProperty(ControlProperty).SetValue(control, ControlPropertyValue, null); } phMain.Controls.Add(control); if (control is IPageTemplateTitle) { this.Title = ((IPageTemplateTitle)control).Modify(this.Title); } } BindData(); }
/// 重写LoadControl,带参数。 /// <summary> /// 重写LoadControl,带参数。 /// </summary> private System.Web.UI.UserControl LoadControl(string UserControlPath, params object[] constructorParameters) { List <Type> constParamTypes = new List <Type>(); foreach (object constParam in constructorParameters) { constParamTypes.Add(constParam.GetType()); } System.Web.UI.UserControl ctl = Page.LoadControl(UserControlPath) as System.Web.UI.UserControl; System.Reflection.ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray()); if (constructor == null) { throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString()); } else { constructor.Invoke(ctl, constructorParameters); } return(ctl); }
protected void Page_Load(object sender, System.EventArgs e) { // Styles UtilHelper.RegisterCssStyleSheet(Page, "~/Layouts/en-US/styles/windows.css"); UtilHelper.RegisterCssStyleSheet(Page, "~/Themes/XP/Theme.css"); UtilHelper.RegisterCssStyleSheet(Page, "~/Styles/Asp.css"); // Scripts UtilHelper.RegisterScript(Page, "~/Layouts/en-US/browser.js"); RegisterScrollScript(Page, PageX.ClientID, PageY.ClientID); Response.Cache.SetNoStore(); LocRM = new ResourceManager("Mediachase.Ibn.WebAsp.App_GlobalResources.Resources.Template", typeof(PageTemplatePublic).Assembly); // Default Settings printScript.Visible = false; frmMain.Visible = true; lblSiteName.Text = LocRM.GetString("ISPAdmin"); body.Attributes.Add("onload", "javascript:ScrollIt()"); //frmMain.Enctype = this.enctype; if (controlName != "") { System.Web.UI.UserControl control = (System.Web.UI.UserControl)LoadControl(controlName); if (ControlProperty != null && ControlPropertyValue != null) { control.GetType().BaseType.GetProperty(ControlProperty).SetValue(control, ControlPropertyValue, null); } phMain.Controls.Add(control); if (control is IPageTemplateTitle) { this.Title = ((IPageTemplateTitle)control).Modify(this.Title); } } BindData(); }
/// <summary> /// Loads a user control with a constructor with a signature matching the supplied params /// Control must implement a blank default constructor as well as the custom one or we will error /// </summary> /// <param name="templateControl">Template control base object</param> /// <param name="controlPath">Path to the user control</param> /// <param name="constructorParams">Parameters for the constructor</param> /// <returns></returns> public static UserControl LoadControl(this TemplateControl templateControl, string controlPath, params object[] constructorParams) { List <Type> constParamTypes = new List <Type>(); foreach (object constParam in constructorParams) { constParamTypes.Add(constParam.GetType()); } UserControl ctl = templateControl.LoadControl(controlPath) as UserControl; // Find the relevant constructor ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray()); //And then call the relevant constructor if (constructor == null) { throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString()); } constructor.Invoke(ctl, constructorParams); // Finally return the fully initialized UC return(ctl); }
/// <summary> /// Hides the specified u. /// </summary> /// <param name="u">The u.</param> public static void Hide(UserControl u) { u.Page.ClientScript.RegisterClientScriptBlock(u.GetType(), "busyindicatorhide", "sap.ui.core.BusyIndicator.hide();", true); }
private void InitializeUserControl(UserControl instance) { if (!this.alreadyInitializedControls.Contains(instance)) { // ASP.NET creates a sub type for UserControls with all the mark up, but this is not the // type that a user can register and not always a type that can be initialized. Type type = instance.GetType().BaseType; this.InitializeInstance(type, instance); // Ensure every user control is only initialized once. this.alreadyInitializedControls.Add(instance); } }
/// <summary> /// Displays the real time notification. /// </summary> /// <param name="control">The control.</param> /// <param name="content">The content.</param> public void DisplayRealTimeNotification(UserControl control, string content) { control.Page.ClientScript.RegisterStartupScript(control.GetType(), "alertifyNotification", "alertify.log('{0}')".FormatWith(content), true); }
/// <summary> /// Displays the real time error. /// </summary> /// <param name="control">The control.</param> /// <param name="content">The content.</param> public void DisplayRealTimeError(UserControl control, string content) { control.Page.ClientScript.RegisterStartupScript(control.GetType(), "alertifyError", "alertify.error('"+ content + "')", true); }
public CmsControlParameterDependency(System.Web.UI.UserControl control, string[] requiredParameterKeys) { ControlName = control.GetType().Name; keys = requiredParameterKeys; existsMode = ExistsMode.MustExist; }
/// <summary> /// Registers a raw external css or js file. This should be used if the file is already minimized /// </summary> /// <param name="control">The control.</param> /// <param name="scriptName">Name of the script.</param> /// <param name="rawScript">The raw script.</param> public void RegisterRawScript(UserControl control, string scriptName, string rawScript) { Contract.Requires(control != null); control.Page.ClientScript.RegisterClientScriptBlock(control.GetType(), scriptName, string.Format("{0}", rawScript)); }
/// <summary> /// Displays the real time success. /// </summary> /// <param name="control">The control.</param> /// <param name="content">The content.</param> public void DisplayRealTimeSuccess(UserControl control, string content) { control.Page.ClientScript.RegisterStartupScript(control.GetType(), "alertifySuccess", "alertify.success('{0}')".FormatWith(content), true); }
public CmsControlParameterDependency(System.Web.UI.UserControl control, string[] parameterKeys, ExistsMode parameterKeysExistsMode) { ControlName = control.GetType().Name; keys = parameterKeys; existsMode = parameterKeysExistsMode; }
/// <summary> /// Registers a Js Script at the header of a page. Can use minimization and external files based on parameters passed /// to function. /// </summary> /// <param name="control">The control.</param> /// <param name="scriptName">Name of the script.</param> /// <param name="script">The script.</param> /// <param name="minimized">if set to <c>true</c> [minimized].</param> /// <param name="isExternalFile">if set to <c>true</c> [is external file].</param> public void RegisterClientScriptBlock(UserControl control, string scriptName, string script, bool minimized = false, bool isExternalFile = false) { Contract.Requires(control != null); if (minimized) { script = this.MinimizeJsCode(script); } if (isExternalFile) { //TODO: verifiy map path script = File.ReadAllText(this.RapContext.MapPath(script)); } control.Page.ClientScript.RegisterClientScriptBlock(control.GetType(), scriptName, string.Format("<script>{0}</script>", script)); }