By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Mar 29 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
move your page load code to prerender

-- bruce (sqlwork.com)

ri*******************@googlemail.com wrote:
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.
Mar 29 '07 #2

P: n/a
On Mar 29, 11:24 pm, ricardo.sobral.san...@googlemail.com wrote:
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
Mar 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.