1: using System;2: using System.Data;3: using System.Configuration;4: using System.Web.UI;5: using System.Web.UI.WebControls;6: using umbraco.cms.businesslogic;7:8: namespace OrbitOne.Umbraco9: {10: public abstract class BaseUserControl : UserControl11: {12: protected BaseUserControl()13: {14: this.Init += Page_Init;15: }16:17: protected void Page_Init(object sender, EventArgs e)18: {19: DictionaryId = this.ToString();20:21: if (string.IsNullOrEmpty(DictionaryId))22: throw new Exception("DictionaryId cannot be null or empty when creating translation labels");23:24: if (Request["addtodictionary"] != null)25: {26: CreateDictionaryItems();27: }28:29: SetTranslation();30: }31:32: protected void DisableButtonWhileSubmitting(Button button, string validationGroup)33: {34: var sbValid = new System.Text.StringBuilder();35: sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");36: sbValid.Append("if (Page_ClientValidate('" + validationGroup + "') == false) { return false; }} ");37: sbValid.Append("this.disabled = true;");38:39: //GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.40: sbValid.Append(Page.GetPostBackEventReference(button));41: sbValid.Append(";");42: button.Attributes.Add("onclick", sbValid.ToString());43: }44:45: #region UmbracoDictionaryFunctions46:47: private void SetTranslation()48: {49: if (!IsPostBack)50: {51: setCopy(this.Controls);52: }53: }54:55: private void CreateDictionaryItems()56: {57: createDictionaryItems(this.Controls);58: Response.Write("Dictionary Items Created");59: }60:61: //loop all controls and set text62: public void setCopy(ControlCollection controls)63: {64:65: foreach (Control ctrl in controls)66: {67:68: if (ctrl is Panel)69: {70: setCopy(ctrl.Controls);71: }72:73: if (ctrl is Literal)74: {75: if (umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID) != string.Empty)76: {77: ((Literal)ctrl).Text = umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID);78: }79: }80:81: if (ctrl is HyperLink)82: {83: if (umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID) != string.Empty)84: {85: ((HyperLink)ctrl).Text = umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID);86: }87: }88:89: if (ctrl is Button)90: {91: if (umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID) != string.Empty)92: {93: ((Button)ctrl).Text = umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID);94: }95:96: }97:98: if (ctrl is CheckBox)99: {100: if (umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID) != string.Empty)101: {102: ((CheckBox)ctrl).Text = umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID);103: }104: }105:106: if (ctrl is Label)107: {108: if (umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID) != string.Empty)109: {110: ((Label)ctrl).Text = umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID);111: }112: }113:114: if (ctrl is BaseValidator)115: {116: if (umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID) != string.Empty)117: {118: ((BaseValidator)ctrl).Text = umbraco.library.GetDictionaryItem(DictionaryId + "." + ctrl.ID);119: }120: }121: }122: }123:124: //loop all controls and create dictionary Item125: public void createDictionaryItems(ControlCollection Controls)126: {127: foreach (Control ctrl in Controls)128: {129:130: if (ctrl is Panel)131: {132: createDictionaryItems(ctrl.Controls);133: }134:135: if (ctrl is Literal)136: {137: createDictionaryItem(DictionaryId + "." + ctrl.ID, ((Literal)ctrl).Text);138: }139:140: if (ctrl is HyperLink)141: {142: createDictionaryItem(DictionaryId + "." + ctrl.ID, ((HyperLink)ctrl).Text);143: }144:145: if (ctrl is Button)146: {147: createDictionaryItem(DictionaryId + "." + ctrl.ID, ((Button)ctrl).Text);148: }149:150: if (ctrl is CheckBox)151: {152: createDictionaryItem(DictionaryId + "." + ctrl.ID, ((CheckBox)ctrl).Text);153: }154:155: if (ctrl is Label)156: {157: createDictionaryItem(DictionaryId + "." + ctrl.ID, ((Label)ctrl).Text);158: }159:160: if (ctrl is BaseValidator)161: {162: createDictionaryItem(DictionaryId + "." + ctrl.ID, ((BaseValidator)ctrl).Text);163: }164: }165: }166:167:168: //create dictionaryItem169: private void createDictionaryItem(string name, string defaulttext)170: {171: try172: {173:174: Dictionary.DictionaryItem.addKey(name, defaulttext);175:176: Response.Write("added " + name + "<br/>");177: }178: catch179: {180: //allready exists181: }182: }183:184: //identifier for umbraco dictionary185: //string dictionaryId = "frmLoginLogout";186: public string DictionaryId { get; set; }187:188: #endregion189: }190: }191:
Wednesday, December 1, 2010
test something
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment