Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery modified Hidden Field Value is empty when posted back to the server
    primarykey
    data
    text
    <p>Summary: I have a web control that is dynamically added to the page. The control has a HiddenField child control. I am passing the control's ClientID to a jquery widget that is setting the value to a string (json converted to string). When the form is posted back to the server, the value of the HiddenField is a blank string. I value is in the Request.Form[<em>UniqueID</em>] object. The value is making it back to the server. The problem is that, I don't have access to the Request object when I need the value without modifying a lot of legacy code.</p> <p>The strange thing is that the selectmany control is the one I am having a problem with, but it inherits from the SelectOne that is working properly. I think I am doing something wrong in the selectmany class because even if I try to push a value into the SelectOneHiddenValue it does not work ,but it works properly when the SelectOne uses it.</p> <p>SelectOne:</p> <pre><code>[ToolboxData("&lt;{0}:SelectOne runat=server&gt;&lt;/{0}:SelectOne&gt;")] public class SelectOne : Panel, IControl,ISelectOne { #region structure private readonly Panel _selectOneTextboxContainer = new Panel(); protected readonly TextBox SelectOneTextbox = new TextBox(); protected readonly HiddenField SelectOneHiddenValue = new HiddenField(); private readonly Panel _selectOneDropdownImageContainer = new Panel(); private readonly Image _selectOneDropDownImage = new Image(); #endregion private readonly IList&lt;LookupItem&gt; _selectedItems = new List&lt;LookupItem&gt;(); #region properties public IList&lt;LookupItem&gt; SelectedItems { get { return _selectedItems; } } public bool MultiSelect { get; set; } public DisplayOption Display { get; set; } public string Name { get; set; } [DefaultValue(0)] public int LookupValueOrgID { get { EnsureChildControls(); return Convert.ToInt32(String.IsNullOrEmpty(SelectOneHiddenValue.Value) ? "0" : SelectOneHiddenValue.Value); } set { EnsureChildControls(); SelectOneHiddenValue.Value = value.ToString(); } } [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { EnsureChildControls(); return SelectOneTextbox.Text; } set { EnsureChildControls(); SelectOneTextbox.Text = value; } } /// &lt;summary&gt; /// The minimum number of characters a user has to type before the autocompleter activates. /// &lt;/summary&gt; [Bindable(true)] [Category("Appearance")] [DefaultValue(1)] [Localizable(true)] public int MinChars { get { int b = (ViewState["MinChars"] == null ? 1 : (int)ViewState["MinChars"]); return b; } set { ViewState["MinChars"] = value; } } /// &lt;summary&gt; /// The number of backend query results to store in cache. If set to 1 (the current result), no caching will happen. Must be &gt;= 1. /// &lt;/summary&gt; [Bindable(true)] [Category("Appearance")] [DefaultValue(10)] [Localizable(true)] public int CacheLength { get { int b = (ViewState["CacheLength"] == null ? 10 : (int)ViewState["CacheLength"]); return b; } set { ViewState["CacheLength"] = value; } } public string OuterMarkupClientID { get { return "SelectOne_Container" + ClientID; } } /// &lt;summary&gt; /// If true, target input text is appended to /// If false, target input text is replaced /// &lt;/summary&gt; public bool AppendSelectedTextToInput { get; set; } public virtual string ContainerClass { get { return "SelectOneContainer"; } } #endregion #region constructor public SelectOne() { SetCssClasses(); } #endregion #region lifecycle overrides protected override void CreateChildControls() { base.CreateChildControls(); AddChildrenToControlCollection(); } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); SetupClientEvents(); ControlHelper.AddRequiredControl(this); var resourceName = string.Empty; var cs = Page.ClientScript; resourceName = "UI.Controls.resources.images.DropDownButton.gif"; _selectOneDropDownImage.ImageUrl = cs.GetWebResourceUrl(GetType(), resourceName); SelectOneTextbox.Attributes.Add("lookupOrgID", LookupOrgID.ToString()); SelectOneTextbox.Attributes.Add("cacheLength", CacheLength.ToString()); SelectOneTextbox.Attributes.Add("service", Service); SelectOneTextbox.Attributes.Add("selectOneTextboxId", SelectOneTextbox.ClientID); SelectOneTextbox.Attributes.Add("selectOneHiddenValueId",SelectOneHiddenValue.ClientID); } #endregion #region private helpers private void SetCssClasses() { this.CssClass = ContainerClass + " AutocompleteContainer"; _selectOneDropDownImage.CssClass = "SelectOneDropDownImage"; SelectOneTextbox.CssClass = "SelectOneTextbox QuantifiTextBox"; _selectOneTextboxContainer.CssClass = "SelectOneTextboxContainer"; _selectOneDropdownImageContainer.CssClass = "SelectOneDropDownImageContainer"; } private void SetupClientEvents() { ControlHelper.RegisterAutoCompleteScript(this); var resourceName = "UI.Controls.resources.scripts.SelectOne.js"; string js; using (var sr = new StreamReader(GetType().Assembly.GetManifestResourceStream(resourceName))) { js = sr.ReadToEnd(); sr.Close(); } ClientScriptProxy.Current.RegisterStartupScript(this, typeof(SelectOne), "SelectOneJS", js, true); _selectOneDropDownImage.Attributes.Add("onclick", "SelectOne_ImageClick('" + SelectOneTextbox.ClientID + "');"); } private void AddChildrenToControlCollection() { _selectOneTextboxContainer.Controls.Add(SelectOneTextbox); this.Controls.Add(_selectOneTextboxContainer); _selectOneDropdownImageContainer.Controls.Add(_selectOneDropDownImage); this.Controls.Add(_selectOneDropdownImageContainer); this.Controls.Add(SelectOneHiddenValue); } #endregion } </code></pre> <p>Select Many:</p> <pre><code>[ToolboxData("&lt;{0}:SelectMany runat=server&gt;&lt;/{0}:SelectMany&gt;")] public class SelectMany : SelectOne, ISelectMany { #region structure private readonly Panel _selectedItemsPanel = new Panel(); private readonly HiddenField _selectManyHiddenField = new HiddenField(); public override string ContainerClass { get { return "SelectManyControlContainer"; } } #endregion public SelectMany() { MultiSelect = true; } #region lifecycle overrides protected override void CreateChildControls() { base.CreateChildControls(); _selectManyHiddenField.ID = "SelectedItemsHiddenValue"; this.Controls.Add(_selectedItemsPanel); this.Controls.Add(_selectManyHiddenField); SelectOneTextbox.Attributes.Add("data-multiselect", MultiSelect.ToString()); } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); var resourceName = "jquery.SelectedItemCollection.js"; ClientScriptProxy.Current.RegisterClientScriptInclude(this, Page.ClientScript.GetWebResourceUrl(this.GetType(),resourceName)); var serializer = new JavaScriptSerializer(); var startupScript = String.Format("\n$('#{0}').each(function(){{" + "var selectedPlugin = $(this).SelectedItemCollection(" + " {{" + " itemData: {1}," + " deleteImageUrl: '{2}'," + " selectedTextId: '{3}', " + " hiddenTextFieldId: '{4}' " + " }});}});\n", this.ClientID, serializer.Serialize(SelectedItems), GetDeleteImageUrl(), SelectOneTextbox.ClientID, _selectManyHiddenField.ClientID ); ClientScriptProxy.Current.RegisterStartupScript(this,this.GetType(),"SelectedItemsJs_" + this.ClientID,startupScript,true); } #endregion #region public api public void BindForm() { EnsureChildControls(); this.DataBind(); var jsonString = _selectManyHiddenField.Value; SelectedItems.Clear(); if (!jsonString.IsNullOrEmpty()) { Json.Decode&lt;IEnumerable&lt;LookupItem&gt;&gt;(jsonString).ForEach(li =&gt; SelectedItems.Add(li)); } } #endregion private string GetDeleteImageUrl() { var cs = Page.ClientScript; const string resourceName = "UI.Controls.resources.images.close.gif"; return cs.GetWebResourceUrl(this.GetType(), resourceName); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload