Solved

help with radiobutton code not worky

Posted on 2008-10-06
6
215 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
Technology Partners: 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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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