| | |
Content Changes across pages via Drop-Down Box
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Solved Threads: 0
I'm not sure if I said that clearly enough,
. What I'm trying to do is, seeing as how I'm not able to do a Shopping Cart at the moment, I'm trying to make it so if you select Item33 or something by clicking the 'Order' button, when it redirects to the Order page the Item33 will be the default value in the drop-down box.
Any ideas? Thanks for reading!
. What I'm trying to do is, seeing as how I'm not able to do a Shopping Cart at the moment, I'm trying to make it so if you select Item33 or something by clicking the 'Order' button, when it redirects to the Order page the Item33 will be the default value in the drop-down box.Any ideas? Thanks for reading!
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
send it via form with "post" and request the form there. Otherwise, send it via server form and request it there..
or do it the easy way and just set a session variable and request it there..
Session("selecteditem") = "Item33"
<DropDownList....>
<% if Session("selecteditem") <> "" or Len(Session("selecteditem")) > 1 then %>
<option value="<%= Session("selecteditem") %>" selected><%=Session("selecteditem") %></option>
<% end if %>
</DropDownList...>
(if you're using a control, instead of <option value...> to <asp:ListItem Text="Session..." Value="Session..." />)
Oh, that's on page. If you wish to do it server-side, just do it like below:
DropDownListName.Items.Insert(Session("selecteditem"), Session("selecteditem"))
DropDownListName.SelectedValue = Session("selecteditem")
or do it the easy way and just set a session variable and request it there..

Session("selecteditem") = "Item33"
<DropDownList....>
<% if Session("selecteditem") <> "" or Len(Session("selecteditem")) > 1 then %>
<option value="<%= Session("selecteditem") %>" selected><%=Session("selecteditem") %></option>
<% end if %>
</DropDownList...>
(if you're using a control, instead of <option value...> to <asp:ListItem Text="Session..." Value="Session..." />)
Oh, that's on page. If you wish to do it server-side, just do it like below:
DropDownListName.Items.Insert(Session("selecteditem"), Session("selecteditem"))
DropDownListName.SelectedValue = Session("selecteditem")
Last edited by SheSaidImaPregy; Nov 4th, 2007 at 6:06 am.
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Solved Threads: 0
Thanks,
. I'll give this a shot this evening and will reply further when I get it up and working.
By the way, the "selecteditem" - would that be the name, or...? What I've done is set up a button link that the user will click to get to the order form, so is the name of that button link on the shop page assigned to the session as in Session("buttonLinkName")="Item33" ?
. I'll give this a shot this evening and will reply further when I get it up and working.By the way, the "selecteditem" - would that be the name, or...? What I've done is set up a button link that the user will click to get to the order form, so is the name of that button link on the shop page assigned to the session as in Session("buttonLinkName")="Item33" ?
Last edited by Varelei; Nov 5th, 2007 at 10:50 pm.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Yes, the selecteditem would be the name. Name the session variable anything you would like. I just chose to name it "selecteditem" with the value of the dropdownlist's selected item (item33).
What this session variable should be used for is just keeping selection across pages, UNLESS your postback URL is the new page. If that is the case, then you should just request.form("dropdownlist") and avoid session variables.
Exactly what I mean:
When a user clicks the dropdownlist and selects one value, your backend code is posted back to the same page and turns that selected item into a session variable called "session("selecteditem")". Then, on the order page, the selecteditem session variable is referenced in to the dropdownlist. That is initially what I thought you were asking for.
What I suggest:
Unless this is not possible, do a postbackUrl to your order page. This way you can just reference in whatever you need to by using "request.form" methods. If this is not possible, use session variables or text files to hold your values. Session variables drop periodically so it would be cumbersome to any visitor if their entire shopping cart emptied or what not. You can also use cookies, but lots of people have them disabled, but many more do not. ultimately, I would suggest just loging the person's IP address into a database and hold your information in there. It prevents any lost catastrophes and is.. well I believe to be good and secure, just less efficient.
What this session variable should be used for is just keeping selection across pages, UNLESS your postback URL is the new page. If that is the case, then you should just request.form("dropdownlist") and avoid session variables.
Exactly what I mean:
When a user clicks the dropdownlist and selects one value, your backend code is posted back to the same page and turns that selected item into a session variable called "session("selecteditem")". Then, on the order page, the selecteditem session variable is referenced in to the dropdownlist. That is initially what I thought you were asking for.
What I suggest:
Unless this is not possible, do a postbackUrl to your order page. This way you can just reference in whatever you need to by using "request.form" methods. If this is not possible, use session variables or text files to hold your values. Session variables drop periodically so it would be cumbersome to any visitor if their entire shopping cart emptied or what not. You can also use cookies, but lots of people have them disabled, but many more do not. ultimately, I would suggest just loging the person's IP address into a database and hold your information in there. It prevents any lost catastrophes and is.. well I believe to be good and secure, just less efficient.
•
•
Join Date: Sep 2007
Posts: 9
Reputation:
Solved Threads: 0
Let me put it this way. I'm very new to ASP.NET, and I'm using controls at the moment. Is this the easiest way, considering I'm still in the progress of learning and practising ASP.NET, or is there an easier method? I'm still very willing to use the Session method, though. I'm adding to your reputation for helping me thus far,
.
Oh, and the drop-down list is part of the Order Form. I wish it to be so that on the product page, when the button is clicked, the user proceeds automatically do the order form with the product name drop-down value to be selected. Like, a Ceramic Pot might have a value of 1 outside of the drop-down, and I wish that value to be picked up, so that the drop-down box will display the item with a value of 1 as default - so the user doesn't need to select the item manually. I would like it to be so that the user doesn't need to search through the list and click an item. And this isn't a shopping cart really, it's just an order form to order a product. I'm nowhere near knowledgeable enough to develop something that complex. In other words, I wish the drop-down to change the default displayed value within it according to the link that is clicked. Sort of like changing a picture dynamically with 3 links.
.Oh, and the drop-down list is part of the Order Form. I wish it to be so that on the product page, when the button is clicked, the user proceeds automatically do the order form with the product name drop-down value to be selected. Like, a Ceramic Pot might have a value of 1 outside of the drop-down, and I wish that value to be picked up, so that the drop-down box will display the item with a value of 1 as default - so the user doesn't need to select the item manually. I would like it to be so that the user doesn't need to search through the list and click an item. And this isn't a shopping cart really, it's just an order form to order a product. I'm nowhere near knowledgeable enough to develop something that complex. In other words, I wish the drop-down to change the default displayed value within it according to the link that is clicked. Sort of like changing a picture dynamically with 3 links.
Last edited by Varelei; Nov 7th, 2007 at 12:51 am.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Then, the easiest solution for you, use the session variable. Have the page postback to you with a form runat=server tag. do this for your submit button:
ASP.NET Syntax (Toggle Plain Text)
<script language="vb" runat="server"> Sub btnSubmit_Click(ByVal S as Sender, ByVal E As EventArgs) Session("selectedItem") = Trim(yourdropdownlistname.SelectItem.Text) response.redirect("order.aspx") 'or if it is all on the same server, use the below line: Server.Transfer("order.aspx") End Sub </script> <form runat="server". ... ... <asp:Button id="btnSubmit" onClick="btnSubmit_Click" Text="proceed to order" runat="server" /> </form> '''''''''''''''''''''''''''''' Order page: <script language="vb" runat="server"> Sub Page_Load(ByVal S As Sender, ByVal E As EventArgs) yourotherdropdownlistname.Items.FindByValue(Session("selectedItem")).Selected = True End Sub </script>
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Now the above will throw an error to your page if the SelectedItem is not found on your order page. If you wish to bypass it, just throw an easy if else statement and trade out the script above for this one:
This will try to set the value, and if the value is not found on your dropdownlist, then your user will have to select it himself. This will not throw an error.
ASP.NET Syntax (Toggle Plain Text)
<script language="vb" runat="server"> Sub Page_Load(ByVal S As Sender, ByVal E As EventArgs) Dim ddl As List Item ddl = yourotherdropdownlistname.Items.FindByValue(Session("selectedItem")) if Not ddl is Nothing then ddl.Selected = True end if End Sub </script>
![]() |
Similar Threads
- login box not working (JavaScript / DHTML / AJAX)
- Easy? Image in Form content? (JavaScript / DHTML / AJAX)
- Drop down box won't shut off video on reverse in IE (JavaScript / DHTML / AJAX)
- I Trade Links in Content Article Pages! (Relevant Link Exchanges)
- Coding for drop down boxes (ColdFusion)
- Drop down box not working (ASP.NET)
- Bidding for content pages (Pay-Per-Click Advertising)
- Time out web pages w/text or drop boxes (Networking Hardware Configuration)
Other Threads in the ASP.NET Forum
- Previous Thread: How to split datetime format?
- Next Thread: Hide Reporting Services Textbox
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# c#gridviewcolumn cac checkbox click commonfunctions confirmationcodegeneration content courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dialog dropdownlist dynamically edit expose fileuploader fill flash formatdecimal forms formview gridview gudi homeedition iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers






