Page Load is first then Radiobuttonlist.selecteditemChanged, can we change this?

  • Thread starter ricardo.sobral.santos
  • Start date
R

ricardo.sobral.santos

Hello,

I am trying to get the value of the radiobuttonlist. The problem is
that I need it to be unselected at every page load. The
radiobuttonlist is set to autopostback (true).
My idea is simple. When I select a value, I get it, insert something
into the database with that value and the page loads again with
different data. Imagine a questionnaire and every page load a random
question would be load on screen and when the user clicks the
radiobutton list, I get the value, insert into the database and only
after I do the page_load again. Is there any way of doing this without
a button, and setting the selecteditemchanged to fire first then the
page_load?

Tks for the help.

The code is simple!


'My Page load is working just the way I want it!
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
RadioButtonList1.ClearSelection() ' I need it to be clear
each time!
leftPanel.Visible = False
Dim users As New ArrayList
users = User_.ArrayOfUsers
Session.Add("users", users)
Session.Add("i", 0)

i = 0
details = User_.getQuestions(users.Item(i))
Image.ImageUrl = details(1).ToString
lblLastChecked.Text = details(3).ToString
details.Clear()
'users.Clear()
Else
'RadioButtonList1.ClearSelection()
i = CType(Session("i"), Integer)

Dim users_tmp As ArrayList
users_tmp = CType(Session("users"), ArrayList)

If (i < users_tmp.Count - 1) Then
detailsAfterRating =
User_.getQuestions(users_tmp.Item(i))
details = User_.getQuestions(users_tmp.Item((i + 1)))

Image.ImageUrl = details(1).ToString
lblLastChecked.Text = details(3).ToString

RatedImage.ImageUrl = detailsAfterRating(2).ToString
lblRating.Text = detailsAfterRating(5).ToString
lblPastRate.Text = Session("youRated")
i = (i + 1)
Session.Add("i", i)
'details.Clear()
'detailsAfterRating.Clear()
leftPanel.Visible = True
Else
Response.Redirect("Homepage.aspx")
End If


End If
End Sub







'This works fine, but only after the page_load. So the first time is
ok, but the second time I need it to be clear and to do something
before it goes to page_load again.

Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
RadioButtonList1.SelectedIndexChanged
Dim answer As String
answer = RadioButtonList1.SelectedValue.ToString

'Code for inserting into database...

End Sub


Tks for all the help.
 
G

Guest

Hello,

I am trying to get the value of the radiobuttonlist. The problem is
that I need it to be unselected at every page load. The
radiobuttonlist is set to autopostback (true).
My idea is simple. When I select a value, I get it, insert something
into the database with that value and the page loads again with
different data. Imagine a questionnaire and every page load a random
question would be load on screen and when the user clicks the
radiobutton list, I get the value, insert into the database and only
after I do the page_load again. Is there any way of doing this without
a button, and setting the selecteditemchanged to fire first then the
page_load?

Tks for the help.

The code is simple!

'My Page load is working just the way I want it!
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
RadioButtonList1.ClearSelection() ' I need it to be clear
each time!
leftPanel.Visible = False
Dim users As New ArrayList
users = User_.ArrayOfUsers
Session.Add("users", users)
Session.Add("i", 0)

i = 0
details = User_.getQuestions(users.Item(i))
Image.ImageUrl = details(1).ToString
lblLastChecked.Text = details(3).ToString
details.Clear()
'users.Clear()
Else
'RadioButtonList1.ClearSelection()
i = CType(Session("i"), Integer)

Dim users_tmp As ArrayList
users_tmp = CType(Session("users"), ArrayList)

If (i < users_tmp.Count - 1) Then
detailsAfterRating =
User_.getQuestions(users_tmp.Item(i))
details = User_.getQuestions(users_tmp.Item((i + 1)))

Image.ImageUrl = details(1).ToString
lblLastChecked.Text = details(3).ToString

RatedImage.ImageUrl = detailsAfterRating(2).ToString
lblRating.Text = detailsAfterRating(5).ToString
lblPastRate.Text = Session("youRated")
i = (i + 1)
Session.Add("i", i)
'details.Clear()
'detailsAfterRating.Clear()
leftPanel.Visible = True
Else
Response.Redirect("Homepage.aspx")
End If

End If
End Sub

'This works fine, but only after the page_load. So the first time is
ok, but the second time I need it to be clear and to do something
before it goes to page_load again.

Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
RadioButtonList1.SelectedIndexChanged
Dim answer As String
answer = RadioButtonList1.SelectedValue.ToString

'Code for inserting into database...

End Sub

Tks for all the help.

Simply redesign it a little bit, as per

Sub Page_Load(...)

If Not Page.IsPostBack Then
LoadNewQuestion()
End If

End Sub

Sub RadioButtonList1_SelectedIndexChanged
'Code for inserting into database...
......
LoadNewQuestion()
End Sub

Sub LoadNewQuestion()
RadioButtonList1.ClearSelection()
' Loading new question
.......
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top