Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

help with radiobutton code not worky

Posted on 2008-10-06
6
Medium Priority
?
233 Views
Last Modified: 2010-04-14
look at my 2 events below.   on page load my radiobutton gets populated based on that statement fine.   my issue is that on click event, whtever i select is not creating the session.  what am i missing?

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Session("bed") = "Manual" Then
            Me.Head.Items.Clear()
            Me.Head.Items.Add(New ListItem("LT10", "LT10"))
            Me.Head.Items.Add(New ListItem("LT15", "LT15"))
            Me.Head.Items.Add(New ListItem("LT28", "LT28"))
            Me.Head.Items.Add(New ListItem("LT40", "LT40"))
 
        Else
            Me.Head.Items.Clear()
            Me.Head.Items.Add(New ListItem("LT40", "LT40"))
            Me.Head.Items.Add(New ListItem("40H", "40H"))
            Me.Head.Items.Add(New ListItem("40SH", "40SH"))
            Me.Head.Items.Add(New ListItem("40HD", "40HD"))
            Me.Head.Items.Add(New ListItem("50", "50"))
            Me.Head.Items.Add(New ListItem("LT70", "LT70"))
        End If
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("head") = Head.SelectedValue
        Response.Redirect("step3.aspx?id=" + Head.SelectedValue)
    End Sub
0
Comment
Question by:gianitoo
  • 3
  • 3
6 Comments
 
LVL 1

Author Comment

by:gianitoo
ID: 22654239
please help me!!!!
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 22657351
First thing i noticed that you are using different session names  while creating a session and a different name while accessing it.

I.e. when you are creating the session you specified session name as "head", and when u are retrieving the session value you typed "bed".

Are you doing this intentionally ??

=========

if yes then are u getting the problem in creating the sessions ??


0
 
LVL 1

Author Comment

by:gianitoo
ID: 22658419
That is different.  bed comes before this page and if stament meets criteria the list fills.  
my issue  is that i am not able to pick up this value   Head.SelectedValue after choosing an option in my radiobutton.  

do you see anything wrong in code below that generates the list?
Me.Head.Items.Clear()
            Me.Head.Items.Add(New ListItem("LT40", "LT40"))
            Me.Head.Items.Add(New ListItem("40H", "40H"))
            Me.Head.Items.Add(New ListItem("40SH", "40SH"))
            Me.Head.Items.Add(New ListItem("40HD", "40HD"))
            Me.Head.Items.Add(New ListItem("50", "50"))
            Me.Head.Items.Add(New ListItem("LT70", "LT70"))
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 22658498
Put  your page_load code in the Page.IsPostback condition.

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

If Page.IsPostback=false Then

        If Session("bed") = "Manual" Then
            Me.Head.Items.Clear()
            Me.Head.Items.Add(New ListItem("LT10", "LT10"))
            Me.Head.Items.Add(New ListItem("LT15", "LT15"))
            Me.Head.Items.Add(New ListItem("LT28", "LT28"))
            Me.Head.Items.Add(New ListItem("LT40", "LT40"))
 
        Else
            Me.Head.Items.Clear()
            Me.Head.Items.Add(New ListItem("LT40", "LT40"))
            Me.Head.Items.Add(New ListItem("40H", "40H"))
            Me.Head.Items.Add(New ListItem("40SH", "40SH"))
            Me.Head.Items.Add(New ListItem("40HD", "40HD"))
            Me.Head.Items.Add(New ListItem("50", "50"))
            Me.Head.Items.Add(New ListItem("LT70", "LT70"))
        End If

End If

End Sub



    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("head") = Head.SelectedValue
        Response.Redirect("step3.aspx?id=" + Head.SelectedValue)
    End Sub
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22658557
you know what,  the error was that  i did not have  
 If Not IsPostBack Then
end if

why did i need that inside my code on page load for it to pick up the selection?
0
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 2000 total points
ID: 22658596
actually the page_load is called on each server control's click event.

So see it like this. (Old thing, your old code flow)

1) When page loads, u fill the list
2) you clicks the button, first the page_load will execute
3) List cleared and repopulated and hence your old selected value is now no more.
4) button click is executed, because no value is selected nothing is the output.

By specifing the the ispostback, the list fill be filled only the first time when page loads, for all other page-load events in the same page the list will not be repopulated.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question