Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Reference a control in the transformation from a user control View modes: 
User avatar
Certified Developer 8
Certified Developer 8
richard - 6/23/2010 10:34:51 PM
   
Reference a control in the transformation from a user control
Hi there

I am using a usercontrol in a transformation.

Within that same transformation I have a DropDownList. I want to be able to get the selected value from the dropdownlist from the code behind of the usercontrol.

I have tried:

DropDownList q = (DropDownList)Page.FindControl("ProductQuantity");

// Response.Write(q.SelectedItem.Value.ToString());

But get object reference not set ...

Any help would be greatly appreciated.

Richard

User avatar
Member
Member
kentico_pavelk - 6/25/2010 4:01:48 AM
   
RE:Reference a control in the transformation from a user control
Hi Richard,

Could you please post here the transformation and code of the control? I tried to use a control in a transformation and didn't encounter any problem with selected value.


Best regards,
Pavel Knotek

User avatar
Certified Developer 8
Certified Developer 8
richard - 6/26/2010 11:19:03 PM
   
RE:Reference a control in the transformation from a user control
Gidday Pavel

Here it is, I am trying to get the value of the dropdownlist control (bold) in the transformation in the code behind of the control called: RubysShoppingCartItemSelector.ascx (bold)

Cheers

Richard


<%@ Register Src="~/CMSModules/Ecommerce/Controls/ProductOptions/RubysShoppingCartItemSelector.ascx" TagName="CartItemSelector" TagPrefix="uc1" %>
<!-- NEW CODE -->

<div id="twocolumns">
<!-- content -->
<div id="content">
<!-- title1 -->
<div class="title1">
<h2><%# HTMLEncode(ResHelper.LocalizeString(Convert.ToString(Eval("SKUName")))) %></h2>
</div>
<!-- subttl -->
<div class="subttl">
<p>
<%#Eval("ProductDescription")%></p>
</div>
<!-- order-block -->
<div class="order-block">
<div class="holder">
<!-- left-col -->
<div class="left-col">
<div class="row nostyle"> <span><%# Eval("ProductPackUnits") %> - <%# Eval("ProductPackSize") %></span>
<p>Weight - <%# Eval("ProductWeight") %> <%# Eval("ProductWeightUnits") %></p>
<span class="spacer">|</span> </div>
<div class="row"> <span><%# EcommerceFunctions.GetFormatedPrice(Eval("SKUPrice"), Eval("SKUDepartmentID")) %> </span>
<p>Price</p>
</div>
</div>
<!-- right-col -->
<div class="right-col">
<div class="row">
<p>Quantity</p>
<div class="quantity-form">

<fieldset>
<asp:DropDownList ID="ProductQuantity" runat="server" CssClass="sel">
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
<asp:ListItem Text="4" Value="4" />
<asp:ListItem Text="5" Value="5" />
</asp:DropDownList>

</fieldset>

</div>
</div>
<div class="row"> <span><%# EcommerceFunctions.GetFormatedPrice(Eval("SKUPrice"), Eval("SKUDepartmentID")) %> </span>
<p>Total</p>
</div>
</div>
</div>
<uc1:CartItemSelector id="cartItemSelector" runat="server" SKUID='<%# ValidationHelper.GetInteger(Eval("SKUID"), 0) %>' SKUEnabled='<%# ValidationHelper.GetBoolean(Eval("SKUEnabled"), false) %>' AddToCartLinkText="ORDER NOW" />
</div>
<!-- box1 -->
<div class="box1">
<div class="frame-t">
<cc1:CMSRepeater ID="CMSDataList1" runat="server" ClassNames="rubys.recipes" Path="/Recipes/%"
TransformationName="rubys.recipes.productrecipe" SelectTopN="1" OrderBy="NewID()" RelatedNodeIsOnTheLeftSide="true" RelationshipName="isrelatedto">
</cc1:CMSRepeater>
</div>
<!-- about -->
<div class="about">
<%#MyFunctions.GetSupplier(Eval("Supplier"))%>
</div>
</div>
<!-- aside -->
<div class="aside">
<!-- preview -->
<div class="preview"> <img src="~/cmspages/getfile.aspx?nodeguid=<%#Eval("ProductImage")%>&width=239"/>
<div class="zoom"><a href="#">MAGNIFY</a></div>
</div>
<!-- sub-navigation -->
<div class="sub-navigation">
<h3>Product guide</h3>
<ul>
<%# MyFunctions.GetProductGuide()%>
</ul>
</div>
</div>
</div>

User avatar
Member
Member
kentico_pavelk - 7/12/2010 3:50:57 AM
   
RE:Reference a control in the transformation from a user control
Hi Richard,

The easiest way how to solve your issue is putting the dropdown list directly to the CartItemSelector control. Or is there any special reason for the dropdown list being outside the CartItemSelector?

Best regards,
Pavel Knotek

User avatar
Certified Developer 8
Certified Developer 8
richard - 7/12/2010 5:03:12 AM
   
RE:Reference a control in the transformation from a user control
Thanks Pavel

Yeah there was a specific reason why it could not be in the control itself - mainly a layout issue.

Here is the code I am using the find the controls in the parent page - it is a bit of a dog as you need to define the return variable outside the scope of the function .... Cheers

getAllCtl(Page.Controls, "ProductQuantity", "System.Web.UI.WebControls.DropDownList");

public void getAllCtl(ControlCollection ctls, string ctrlID, string ctrlType)
{

//Response.Write("<br>ctrlcount"+ctls.Count.ToString());


//Response.Clear();
//
foreach (Control c in ctls)
{
//controls.Text = controls.Text + "CONTROLS"+c.ToString()+":"+ctls.Count.ToString()+"<br>";
// Response.Write("<br>TYPE"+c.GetType().ToString());
try
{
// Response.Write("<br>NAME" + c.ID.ToString() + "<BR>");
}
catch { }

if (c.GetType().ToString() == ctrlType)
{
if (ctrlType == "System.Web.UI.WebControls.DropDownList")
{
DropDownList tt = c as DropDownList;

if (tt.ID.ToString() == ctrlID)
{

myc = tt;

}

}
else if (ctrlType == "CMS.PortalControls.CMSUpdatePanel")
{

CMS.PortalControls.CMSUpdatePanel tt = c as CMS.PortalControls.CMSUpdatePanel;

if (tt.ID.ToString() == ctrlID)
{

// Response.Write("<BR>MYDROPDOWN:" + tt.ID.ToString());

myc = tt;

}

}




}
else
{
if (myc != null)
{


}
else
{
if (c.HasControls())
{
getAllCtl(c.Controls, ctrlID, ctrlType);
}
}
}

}


}

User avatar
Member
Member
kentico_pavelk - 7/23/2010 2:53:51 AM
   
RE:Reference a control in the transformation from a user control
Hi Richard,

Could you please describe me the reasons why you can't use one control? As for the layout, you can render the HTML tags in the control as well. Searching for one particular control on the page using foreach is not effective. If you describe me your reasons, I will try to suggest better way.


Best regards,
Pavel Knotek