Solved

help with radiobutton code not worky

Posted on 2008-10-06
6
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

751 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