From: Argiris K. <be...@us...> - 2005-12-09 17:07:23
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15535/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Removed ReflectFormControl method. Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** AjaxPanel.cs 9 Dec 2005 14:02:54 -0000 1.34 --- AjaxPanel.cs 9 Dec 2005 17:07:14 -0000 1.35 *************** *** 615,870 **** } - protected void ReflectContainedFormControls (Control container) - { - ArrayList elems = new ArrayList(); - if ( container is IPostBackDataHandler ) - elems.Add (container); - elems.AddRange (Util.GetChildControlsOfType(container, typeof(IPostBackDataHandler), typeof(RenderedByScriptControl), true)); - - for (int i=0; i < elems.Count; i++) - ReflectFormControl (elems[i] as Control); - } - - protected void ReflectLiteralFormControls() - { - for (int i=0; i < this.Controls.Count; i++) - { - if ( ! IsHtmlHolder(this.Controls[i]) ) - ReflectContainedFormControls (this.Controls[i]); - } - } - - #region ReflectFormControl - /// <summary> - /// Compares the value of the form control with the value of the client's - /// form element and sends javascript command to corrent the client's element - /// if necessary. - /// </summary> - /// <param name="control"></param> - protected virtual void ReflectFormControl (Control control) - { - NameValueCollection form = Context.Request.Form; - - if ( control is WebControl ) - { - #region Reflecting for WebControls - - string id = control.UniqueID; - - if ( control is RadioButton ) - { - RadioButton radio = control as RadioButton; - int index = radio.UniqueID.LastIndexOf(':'); - string uniqueGroupName = radio.UniqueID.Substring(0, index + 1) + radio.GroupName; - if ( radio.Checked && form[uniqueGroupName] != radio.ID ) - { - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked=true;\r\n", control.ClientID); - } - else if ( !radio.Checked && form[uniqueGroupName] == radio.ID ) - { - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked=false;\r\n", control.ClientID); - } - } - else if ( control is CheckBox ) - { - if ( !(control.Parent is CheckBoxList) ) - { - CheckBox chkbox = control as CheckBox; - if ( chkbox.Checked != (form[id] != null) ) - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked={1};\r\n", id, (chkbox.Checked) ? "true" : "false"); - } - } - else if ( control is CheckBoxList ) - { - CheckBoxList chklist = control as CheckBoxList; - for (int i=0; i < chklist.Items.Count; i++) - { - string itemid = String.Format("{0}:{1}", id, i); - if ( chklist.Items[i].Selected != (form[itemid] != null) ) - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked={1};\r\n", itemid, (chklist.Items[i].Selected) ? "true" : "false"); - } - } - else if ( control is DropDownList ) - { - DropDownList ddlist = control as DropDownList; - if ( (ddlist.SelectedIndex == -1 && form[id] != null) - || ddlist.SelectedValue != form[id] ) - AjaxCallHelper.WriteSetFieldScript (id, ddlist.SelectedValue); - } - else if ( control is ListBox ) - { - ListBox lstbox = control as ListBox; - if ( ListSelectionMode.Single == lstbox.SelectionMode ) - { - if ( (lstbox.SelectedIndex == -1 && form[id] != null) - || lstbox.SelectedValue != form[id] ) - AjaxCallHelper.WriteSetFieldScript (id, lstbox.SelectedValue); - } - else - { - string[] selections = form.GetValues(id); - bool elemWritten = false; - - // Make selections - for (int i=0; i < lstbox.Items.Count; i++) - { - if (lstbox.Items[i].Selected && Array.IndexOf(selections, lstbox.Items[i].Value) == -1) - { - if ( ! elemWritten ) - { - AjaxCallHelper.WriteFormat ("elem=document.forms[0][\"{0}\"];\r\n", id); - elemWritten = true; - } - AjaxCallHelper.WriteFormat ("elem.options[{0}].selected=true;\r\n", i); - } - } - - // Make unselections - for (int i=0; i < selections.Length; i++) - { - for (int itemi=0; itemi < lstbox.Items.Count; itemi++) - { - if ( lstbox.Items[itemi].Value == selections[i] ) - { - if ( ! lstbox.Items[itemi].Selected ) - { - if ( ! elemWritten ) - { - AjaxCallHelper.WriteFormat ("elem=document.forms[0][\"{0}\"];\r\n", id); - elemWritten = true; - } - AjaxCallHelper.WriteFormat ("elem.options[{0}].selected=false;\r\n", itemi); - } - break; - } - } - } - } - } - else if ( control is RadioButtonList ) - { - RadioButtonList rblist = control as RadioButtonList; - if ( rblist.SelectedIndex == -1 && form[id] != null ) - { - // Clear selection - for (int i=0; i < rblist.Items.Count; i++) - { - if (rblist.Items[i].Value == form[id]) - { - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked=false;\r\n", String.Format("{0}_{1}", control.ClientID, i)); - break; - } - } - } - else if ( rblist.SelectedIndex != -1 && rblist.SelectedValue != form[id] ) - { - // Make selection - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked=true;\r\n", String.Format("{0}_{1}", control.ClientID, rblist.SelectedIndex)); - } - } - else if ( control is TextBox ) - { - TextBox txtbox = control as TextBox; - if ( txtbox.Text != form[id] ) - AjaxCallHelper.WriteSetFieldScript (id, txtbox.Text); - } - - #endregion - } - else if ( control is HtmlControl ) - { - #region Reflecting for HtmlControls - - if ( control is HtmlInputCheckBox ) - { - HtmlInputCheckBox chkbox = control as HtmlInputCheckBox; - if ( chkbox.Checked != (form[chkbox.Name] != null) ) - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked={1};\r\n", chkbox.Name, (chkbox.Checked) ? "true" : "false"); - } - else if ( control is HtmlInputRadioButton ) - { - HtmlInputRadioButton radio = control as HtmlInputRadioButton; - if ( radio.Name != String.Empty ) - { - int index = radio.UniqueID.LastIndexOf(':'); - string uniqueName = radio.UniqueID.Substring(0, index + 1) + radio.Name; - if ( radio.Checked && form[uniqueName] != radio.ID ) - { - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked=true;\r\n", control.ClientID); - } - else if ( !radio.Checked && form[uniqueName] == radio.ID ) - { - AjaxCallHelper.WriteFormat ("document.forms[0][\"{0}\"].checked=false;\r\n", control.ClientID); - } - } - } - else if ( control is HtmlInputText ) - { - HtmlInputText txtbox = control as HtmlInputText; - if ( txtbox.Value != form[txtbox.Name] ) - AjaxCallHelper.WriteSetFieldScript (txtbox.Name, txtbox.Value); - } - else if ( control is HtmlSelect ) - { - HtmlSelect sel = control as HtmlSelect; - if ( ! sel.Multiple ) - { - if ( (sel.SelectedIndex == -1 && form[sel.Name] != null) - || sel.Value != form[sel.Name] ) - AjaxCallHelper.WriteSetFieldScript (sel.Name, sel.Value); - } - else - { - string[] selections = form.GetValues(sel.Name); - bool elemWritten = false; - - // Make selections - for (int i=0; i < sel.Items.Count; i++) - { - if (sel.Items[i].Selected && Array.IndexOf(selections, sel.Items[i].Value) == -1) - { - if ( ! elemWritten ) - { - AjaxCallHelper.WriteFormat ("elem=document.forms[0][\"{0}\"];\r\n", sel.Name); - elemWritten = true; - } - AjaxCallHelper.WriteFormat ("elem.options[{0}].selected=true;\r\n", i); - } - } - - // Make unselections - for (int i=0; i < selections.Length; i++) - { - for (int itemi=0; itemi < sel.Items.Count; itemi++) - { - if ( sel.Items[itemi].Value == selections[i] ) - { - if ( ! sel.Items[itemi].Selected ) - { - if ( ! elemWritten ) - { - AjaxCallHelper.WriteFormat ("elem=document.forms[0][\"{0}\"];\r\n", sel.Name); - elemWritten = true; - } - AjaxCallHelper.WriteFormat ("elem.options[{0}].selected=false;\r\n", itemi); - } - break; - } - } - } - } - } - else if ( control is HtmlTextArea ) - { - HtmlTextArea txtbox = control as HtmlTextArea; - if ( txtbox.Value != form[txtbox.Name] ) - AjaxCallHelper.WriteSetFieldScript (txtbox.Name, txtbox.Value); - } - - #endregion - } - } - #endregion - #region override PutTagOnPageForAjaxCall /// <summary> --- 615,618 ---- |