View Single Post
  #1 (permalink)  
Old March 27th, 2009, 11:15 AM
areed24 areed24 is offline
Authorized User
 
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need to click radio button twice for event to fire

I have a page that has a text field where users enter a number, then they can select either Dollars or Euros and the amount is converted. It works fine except that the user has to click the radio button twice the first time the page loads to get the conversion to fire. Below is my code:

ProtectedSub radio1_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles radio1.SelectedIndexChanged
If Page.IsValid Then
If radio1.SelectedItem.ToString = "Dollars"Then
Dim result AsSingle = 0
Dim crate AsSingle = 0.7836
Dim currency AsSingle = Convert.ToSingle(txtcurrency.Text)
result = currency * crate
lblcurrencyResult.Text = System.Math.Round(Convert.ToDecimal(result), 2) &
" €"
ElseIf radio1.SelectedItem.ToString = "Euros"Then
Dim result AsSingle = 0
Dim crate AsSingle = 1.2762
Dim currency AsSingle = Convert.ToSingle(txtcurrency.Text)
result = currency * crate
lblcurrencyResult.Text =
"$ " & System.Math.Round(Convert.ToDecimal(result), 2)
Else
lblcurrencyResult.Text = ""
EndIf
EndIf
EndSub

Any idea why this is happening?