Solved

help with radiobutton code not worky

Posted on 2008-10-06
6
210 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

8 Experts available now in Live!

Get 1:1 Help Now