I've been working on customizing BuyProductDialog, as my design comps call for four Customer Fields/product Options to appear in a specific order:
1. TextBox control (integer only; requires custom range validator)
2. DropDownList control (if "Other" is selected, a TextBox appears below)
3. DropDownList control (if "Other" is selected, a TextBox appears below)
4. Textbox (all characters permitted--essentially an "add details" field for customer convenience)
I've basically done two things to achieve this, and my issues are each related to the customizations being "lost" on IsPostBack.
Numer one
Description of customization: First, in BuyProductDialog.ascx, I've created #1 as its own repeater above OptionsList, modeled after TemplatesList. (I'll spare you the gorey details of it but basically, in the codebehind, I've customized GetProductTemplateFields() to handle a passed boolean value, determining whether it's "special" has #1 calls for, or just a regular old Customer Field. So TemplatesList_ItemDataBound works for separate repeaters.)
Issue: What I'm encountering is that while the whole repeater functions, range validator and all, whenever PostBack occurs (e.g., Add to Cart) the value is lost. What must I do to store it and pass it to the Cart or Wishlist?
My code:
Code: Select all
<asp:Repeater ID="AttenuationField" runat="server" OnItemDataBound="TemplatesList_ItemDataBound">
<itemtemplate>
<tr>
<th class="rowHeader" >
<span class="custLabel"><%#GetUserName(Container.DataItem)%>:<span class="custRequired">*</span></span>
</th>
<td runat="server">
<asp:TextBox runat="server" ID="Attenuation" Text="" AutoPostBack="false" EnableViewState="true" />
<asp:Label ID="AttenuationUnit" runat="server" Text="dB" />
<!-- CUSTOM: Validates attenuation range based on admin parameters -->
<asp:RangeValidator ID="AttenuationValidator" runat="server" validationgroup="AddToBasket"
ControlToValidate="Attenuation" Type="Integer" autopostback="true" Text="*<br />"
MinimumValue="<%#GetAttMin()%>" MaximumValue="<%#GetAttMax()%>"
ErrorMessage='<%#string.Format("Please enter an attenuation<br />value between {0} and {1}.", GetAttMin(), GetAttMax())%>' />
</td>
</tr>
</itemtemplate>
</asp:Repeater>
Description of customization: As mentioned a TextBox control must appear if user selects "Other" from an OptionsList dropdrown. So within the OptionsList repeater below the last </tr>, I've added a custom HTML control:
Code: Select all
<tr>
<th class='rowHeader'> </th>
<td runat="server">
<input id="<%#GetOtherField(Container.DataItem, 1)%>" name="<%#GetOtherField(Container.DataItem, 1)%>" value="<%#GetOtherField(Container.DataItem, 2)%>" onfocus="<%#GetOtherField(Container.DataItem, 3)%>" onblur="<%#GetOtherField(Container.DataItem, 4)%>" style="display:none"/>
</td>
</tr>
Issue: Again, on PostBack, even if "other" is selected in the DropDownList, the TextBox returns to "display:none" and any values entered are lost. How do I retain these two properties -- text and style -- over the PostBack hump?
Thanks for your help.
Cal