Posted
on Jan 13, 2011
(permalink)
I had an issue a few weeks ago about controls that were added dynamically were not available after postback, but this related to controls in a RadPanelItems contentTemplate and was easily fixed once the templates were reapplied after postback.
However, I've got a similar issue now but in the HeaderTemplate of a dynamically added RadPanelItem.
Imagine I have a list of product bundles. Each of those bundles has a number of items in them. I am adding a RadPanelItem to the RadPanelBar for each one to show the bundle's name etc, and inside the RadPanelItem I am applying a ContentTemplate that has a RadGrid which shows the products in that bundle.
I have built a custom HeaderTemplate to include a TextBox, so that a user can type a number in to select a quantity for each bundle and then a button at the bottom of my page posts back and from there I can see how many of each bundle (and from there calculate how many of each product - a product could be in more than one bundle) has been ordered. An example is shown (very crudely) below...
Bundle One [qtyTextbox]
Product One
Product Two
Product Three
Bundle Two [qtyTextBox]
Product One
Product Four
Product Five
I have tried both applying the templates after postback for the header, and not applying them, for each RadPanelItem but I cannot seem to access the qtyTextbox value. If I apply the template, the textbox gets found by PanelItem.Header.FindControl("qtyTextBox"), but it has an empty Text property (""), and if I dont apply the template, then there simply isn't a textbox, and therefore no value.
In the HeaderTemplate, the textbox is define as below, and the RadPanelBar has EnableViewState = true.
TextBox QuantityTextBox = new TextBox();
QuantityTextBox.ID = "QuantityTextBox";
QuantityTextBox.Attributes["onblur"] = "return CalculateTotal()";
QuantityTextBox.Width = Unit.Pixel(50);
QuantityTextBox.Height = Unit.Pixel(14);
QuantityTextBox.EnableViewState = true;
Does anyone have any suggestions as to what I should try next?