Trouble pulling a selecteditem.text value out of a

marnenlk

New Member
I have a web form (.ascx) that has a Server Side Form. The page is used to generate product details pulling data from a database. Some products have customizations available and some do not. I have two common customizations that I want to give the end user the capability of choosing before they add the item to the cart. I have two Image Buttons, Two Drop Down Boxes, Two Labels, and Two ImageFrames that are either hidden or shown on the Page_Load even depending upon the database information for each product. <BR><BR>When I select for instance Brown Hair Color from DropDown1, and click the imagebutton, I want it to dynamically pull the image path from the database, set the ImageUrl prop of the ImageFrame, and change the ImageFrame.Visible to true. <BR><BR>I have that code right here.<BR><BR>Public Sub btnHairSelect_Click(ByVal sender As Object, ByVal e As system.Web.UI.ImageClickEventArgs)<BR>Dim hairurl As String<BR>hairurl = HairColorList.SelectedItem.Text<BR>imgHairColor.ImageUrl = "CustomizationImages/" & hairurl & ".gif"<BR>imgHairColor.Visible = True<BR>lblHairColor.Text = "You have Selected " & hairurl & " as your Hair Color."<BR>End Sub<BR><BR><BR>The error that I'm having is "Value Null was found where an instance of an object was required" This error occurs at the "hairurl = haircolorlist.selecteditem.text" line. Obviously the form is posting before the variable is saved or something. Its loosing the selected item on the dropdown box. When I press the imagebutton calling the routine I have just listed with that hairurl=haircolorlist.selecteditem.text commented out and the image url hard coded, the drop down box won't retain the selection that I sleceted in it before the image button was clicked. Bascially after postback, I loose all values. <BR><BR>I'm very new to ASP.net, have VB experience with limited asp background as well. I'm sure its something simple, config file or something. Please help!!! :) ThanksIs HairColorList within the webform? If not it wont be available at all to asp.net. <BR><BR>If it is in a form... one question..<BR><BR>Are you just submitting... Using the default value of the pulldown? I think.. in order for the selectedItem property to be set you have to actually select something different. I think when your page first loads you have to specify the item in the listbox you want to be selected first in order to access the selectedItem property. Let me verify this... ok yup.. <BR><BR>Demonstration test.aspx<BR><BR><BR><%@ page language="vb" debug="true" %><BR><script runat="server"><BR><BR> sub page_load(Sender as object,e as eventArgs)<BR> if ispostback then '' if this line were not here error would occur when the page loaded.<BR> Response.Write (poo.selectedItem.text)<BR> end if<BR> end sub<BR></script><BR> <!-- Created: 12/7/2001 3:49:23 PM --><BR><HTML><BR><HEAD><BR> <META NAME="GENERATOR" Content="ASP Express 1.9"><BR> <TITLE>Untitled</TITLE><BR></HEAD><BR><BODY><BR> <form runat="server"><BR> <asp:listbox id="poo" runat="server" autopostback=true><BR> <asp:listitem runat="server" text="1" /><BR> <asp:listitem runat="server" text="2" /><BR><BR> </asp:listbox><BR> </form><BR><BR><BR><BR><BR><BR></BODY><BR></HTML>I was having the same problem yesterday. I found this solution on another message board, and it works for me.<BR><BR>"It looks like you're binding the data every time the page loads. You'll only want to populate the dropdown if the Page.IsPostBack property is false."<BR><BR>good luck,<BR>Deborah
 
Back
Top