Solved

help with radiobutton code not worky

Posted on 2008-10-06
6
199 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now