InstantASP Community Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        


12»»

Retrieving control values from... Expand / Collapse
Author
Message
Posted 19/04/2005 20:56:57


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 22/09/2008 15:59:25
Posts: 693, Visits: 2,418
Hi everyone,

I've been programming for many years, but have just started teaching myself .NET within the last year.. and I have an issue, in which I could use some of your expert advice

(This is developed in vb.net)

I'm populating a Datalist on page load (if not ispostback).  There are are a series of controls, within the datalist (labels, a textbox, a hyperlink, a button & a dropdownlist).

When the button is clicked (CommandName = AddToCart), I'm retrieving the values of these controls and populating some session variables.  It works great for the textbox & dropdownlist, but for some reason I'm unable to retrieve the values from the labels & hyperlink.

The code compiles properly and executes properly, but the values from the labels & hyperlink are blank.

At this point, all of the controls, including the datalist, have enableviewstate = true

Here is the code, that I have within the Itemlist_ItemCommand sub procedure:

**************
If e.CommandName = "AddToCart" Then

   Session("item_id") = CType(e.Item.FindControl("lbl_item_id"), Label).Text
   Session("item_desc") = CType(e.Item.FindControl("hlinkitem_title"), HyperLink).Text
   Session("price") = CType(e.Item.FindControl("price"), Label).Text
   Session("quantity") = CType(e.Item.FindControl("lblqty"), TextBox).Text

   If CType(e.Item.FindControl("ddlsizes"), DropDownList).Enabled = True Then
      Session("size_id") = CType(e.Item.FindControl("ddlsizes"), DropDownList).SelectedItem.Value
      Session("size") = CType(e.Item.FindControl("ddlsizes"), DropDownList).SelectedItem.Text
   Else
      Session("size_id") = "0"
      Session("size") = "No Size"
   End If

End If
***************

Here is the trace, of the itemlist:  (The problem controls seem to be the 'databoundliteralcontrols'...  This is where i could use some learning & your help)...

        Itemlist System.Web.UI.WebControls.DataList 5637 76
            Itemlist:_ctl0 System.Web.UI.WebControls.DataListItem 0 0
                Itemlist:_ctl0:_ctl0 System.Web.UI.LiteralControl 0 0
            Itemlist:_ctl1 System.Web.UI.WebControls.DataListItem 1288 0
                Itemlist:_ctl1:_ctl0 System.Web.UI.LiteralControl 39 0
                Itemlist:_ctl1:image System.Web.UI.WebControls.HyperLink 133 116
                Itemlist:_ctl1:_ctl1 System.Web.UI.LiteralControl 15 0
                Itemlist:_ctl1:title1 System.Web.UI.WebControls.Label 58 0
                    Itemlist:_ctl1:_ctl2 System.Web.UI.DataBoundLiteralControl 5 12
                Itemlist:_ctl1:_ctl3 System.Web.UI.LiteralControl 15 0
                Itemlist:_ctl1:hlinkitem_title System.Web.UI.WebControls.HyperLink 106 76
                    Itemlist:_ctl1:_ctl4 System.Web.UI.DataBoundLiteralControl 35 52
                Itemlist:_ctl1:_ctl5 System.Web.UI.LiteralControl 15 0
                Itemlist:_ctl1:price System.Web.UI.WebControls.Label 58 0
                    Itemlist:_ctl1:_ctl6 System.Web.UI.DataBoundLiteralControl 6 16
                Itemlist:_ctl1:_ctl7 System.Web.UI.LiteralControl 23 0
                Itemlist:_ctl1:lblqty System.Web.UI.WebControls.TextBox 136 0
                Itemlist:_ctl1:_ctl8 System.Web.UI.LiteralControl 24 0
                Itemlist:_ctl1:ddlsizes System.Web.UI.WebControls.DropDownList 0 124
                Itemlist:_ctl1:_ctl9 System.Web.UI.LiteralControl 15 0
                Itemlist:_ctl1:btnbuy System.Web.UI.WebControls.Button 260 68
                Itemlist:_ctl1:_ctl10 System.Web.UI.LiteralControl 15 0
                Itemlist:_ctl1:rval_qty System.Web.UI.WebControls.RangeValidator 289 0
                Itemlist:_ctl1:_ctl11 System.Web.UI.LiteralControl 15 0
                Itemlist:_ctl1:lbl_item_id System.Web.UI.WebControls.Label 59 0
                    Itemlist:_ctl1:_ctl12 System.Web.UI.DataBoundLiteralControl 1 8
                Itemlist:_ctl1:_ctl13 System.Web.UI.LiteralControl 13 0
*****************

Here are the session state traces, that I'm failing to retrieve values. (the dropdownlist and textbox return values correctly, but not the labels & hyperlink)

item_id System.String  
item_desc System.String  
price System.String  

*****************

Along with CType, I have also attempted Directcast, with no luck..

Can anyone offer some much needed advice?

I'm sure I'm doing something stupid, but please be gentle


..:: Bare ::..
http://www.livingformetal.com
Post #5704
Posted 19/04/2005 21:21:05
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 11/06/2008 22:22:08
Posts: 146, Visits: 657
Hey Bare,

Can you show us the HTML code?

--

http://www.the-pork.net ... highly customized version of InstantForum. 

Post #5706
Posted 19/04/2005 21:44:00


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 22/09/2008 15:59:25
Posts: 693, Visits: 2,418
Here is the datalist portion of the html...

<asp:datalist id="Itemlist" runat="server" RepeatDirection="Horizontal" ShowFooter="False" RepeatColumns="3"
       Width="100%" ShowHeader="False">
       <HeaderTemplate>
        Recently Added Items
       </HeaderTemplate>
       <AlternatingItemStyle CssClass="tblinvis"></AlternatingItemStyle>
       <ItemStyle CssClass="tblinvis"></ItemStyle>
       <ItemTemplate>
        <P align="center">
         <asp:HyperLink id=image runat="server" EnableViewState="True" CssClass="btnhyper2" ImageUrl='<%# ConfigurationSettings.AppSettings("lfm_item_image_path")+GetThumbnail(DataBinder.Eval(Container.DataItem, "item_id")) %>' NavigateUrl='<%# "~/items/viewitem.aspx?item="&amp;DataBinder.Eval(Container.DataItem, "item_id") %>'>
         </asp:HyperLink><BR>
         <asp:Label id="title1" runat="server" EnableViewState="True" CssClass="txt1">
          <%# DataBinder.Eval(Container.DataItem, "band_name") %>
         </asp:Label><BR>
         <asp:HyperLink id=hlinkitem_title runat="server" EnableViewState="True" NavigateUrl='<%# "~/items/viewitem.aspx?item="&amp;DataBinder.Eval(Container.DataItem, "item_id") %>'>
          <%# DataBinder.Eval(Container.DataItem, "item_title") %>
         </asp:HyperLink><BR>
         <asp:Label id="price" runat="server" EnableViewState="True" CssClass="txt2">
          <%# "$"+Format(DataBinder.Eval(Container.DataItem, "price"), "##,##0.00") %>
         </asp:Label>&nbsp;&nbsp;
         <asp:TextBox id="lblqty" runat="server" EnableViewState="True" CssClass="txtboxinput" Width="25px"
          Columns="1">1</asp:TextBox>&nbsp; &nbsp;
         <aspropDownList id=ddlsizes runat="server" EnableViewState="True" CssClass="dropdown" Width="100px" DataValueField="size_id" DataTextField="size_desc" DataSource='<%# GetSizes(DataBinder.Eval(Container.DataItem, "item_id")) %>' visible="<%# AreThereSizes %>" >
         </aspropDownList><BR>
         <asp:Button id=btnbuy runat="server" EnableViewState="True" CssClass="btn2" Width="150px" CommandName="AddToCart" Text='<%# CheckStock(DataBinder.Eval(Container.DataItem, "item_id")) %>' enabled="<%# IsThereStock %>" >
         </asp:Button><BR>
         <asp:RangeValidator id="rval_qty" runat="server" EnableViewState="False" CssClass="val" Display="Dynamic"
          ForeColor=" " MinimumValue="1" MaximumValue="999" ControlToValidate="lblqty" ErrorMessage="RangeValidator">Please enter a valid quantity</asp:RangeValidator><BR>
         <asp:Label id="lbl_item_id" runat="server" EnableViewState="True" CssClass="txt1">
          <%# DataBinder.Eval(Container.DataItem, "item_id") %>
         </asp:Label><BR>
       </ItemTemplate>
       <HeaderStyle CssClass="thead"></HeaderStyle>
      </asp:datalist>


..:: Bare ::..
http://www.livingformetal.com
Post #5710
Posted 19/04/2005 21:48:50


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 22/09/2008 15:59:25
Posts: 693, Visits: 2,418
Visual Studio reformats the html and makes it look really pathetic

and I'm pretty new to this...


..:: Bare ::..
http://www.livingformetal.com
Post #5712
Posted 19/04/2005 21:53:56
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 11/06/2008 22:22:08
Posts: 146, Visits: 657
Hmm... for the life of my I can't see it...

Try removing the spaces in the label and the link.. make em all on one line..

just a thought...

--

http://www.the-pork.net ... highly customized version of InstantForum. 

Post #5713
Posted 19/04/2005 21:55:02
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 11/06/2008 22:22:08
Posts: 146, Visits: 657
is price pulling from its label correctly?

--

Edit.. oh never mind. you did say the labels aren't pulling.. duh..

--

http://www.the-pork.net ... highly customized version of InstantForum. 

Post #5715
Posted 19/04/2005 22:20:47


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Customers
Last Login: 22/09/2008 15:59:25
Posts: 693, Visits: 2,418
I tried removing spaces and carriage returns, with no success (plus, Visual Studio just puts them right back anyway)....

Ya... I think i've been looking at this too long... arghhh...

On page load all the controls, within the datalist, bind to the correct data...  So, in testing... before retrieving the values of one of the labels...  I programmatically, changed the value of the label..  then when I retrieve the value of said label... it correctly returns the changed value... 

So, it seems for some reason, that even though the label is displaying and is bound to the correct data.. it truly isn't there to be retrieved.. (of course i'm saying this with the limited experience that i have)...

Any other ideas or suggestions would be greatly appreciated.


..:: Bare ::..
http://www.livingformetal.com
Post #5717
Posted 19/04/2005 22:23:28